From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-media@vger.kernel.org,
Alexey Khoroshilov <khoroshilov@ispras.ru>,
Hans Verkuil <hans.verkuil@cisco.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/4] [media] bt8xx: One function call less in bttv_input_init() after error detection
Date: Sat, 10 Dec 2016 21:48:06 +0100 [thread overview]
Message-ID: <e20a6835-a404-e894-d0d0-a408bfcd7fb6@users.sourceforge.net> (raw)
In-Reply-To: <d9a0777b-8ea7-3f7d-4fa2-b16468c4a1a4@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Dec 2016 09:29:24 +0100
The kfree() function was called in one case by the
bttv_input_init() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.
* Split a condition check for resource allocation failures so that
each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
Link: https://cwe.mitre.org/data/definitions/754.html
Fixes: d8b4b5822f51e2142b731b42c81e3f03eec475b2 ("[media] ir-core: make struct rc_dev the primary interface")
* Adjust a jump target according to the Linux coding style convention.
* Delete an initialisation for the variable "err" at the beginning
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/pci/bt8xx/bttv-input.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/media/pci/bt8xx/bttv-input.c b/drivers/media/pci/bt8xx/bttv-input.c
index 4da720e4867e..9187993d23ea 100644
--- a/drivers/media/pci/bt8xx/bttv-input.c
+++ b/drivers/media/pci/bt8xx/bttv-input.c
@@ -418,15 +418,20 @@ int bttv_input_init(struct bttv *btv)
struct bttv_ir *ir;
char *ir_codes = NULL;
struct rc_dev *rc;
- int err = -ENOMEM;
+ int err;
if (!btv->has_remote)
return -ENODEV;
- ir = kzalloc(sizeof(*ir),GFP_KERNEL);
+ ir = kzalloc(sizeof(*ir), GFP_KERNEL);
+ if (!ir)
+ return -ENOMEM;
+
rc = rc_allocate_device();
- if (!ir || !rc)
- goto err_out_free;
+ if (!rc) {
+ err = -ENOMEM;
+ goto free_ir;
+ }
/* detect & configure */
switch (btv->c.type) {
@@ -569,6 +574,7 @@ int bttv_input_init(struct bttv *btv)
btv->remote = NULL;
err_out_free:
rc_free_device(rc);
+free_ir:
kfree(ir);
return err;
}
--
2.11.0
next prev parent reply other threads:[~2016-12-10 20:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-10 20:45 [PATCH 0/4] [media] bt8xx: Fine-tuning for three functions SF Markus Elfring
2016-12-10 20:48 ` SF Markus Elfring [this message]
2016-12-10 21:29 ` [PATCH 1/4] [media] bt8xx: One function call less in bttv_input_init() after error detection Daniele Nicolodi
2016-12-10 22:10 ` SF Markus Elfring
2016-12-11 21:52 ` Daniele Nicolodi
2016-12-12 7:33 ` SF Markus Elfring
2016-12-12 7:39 ` Daniele Nicolodi
2016-12-12 17:15 ` SF Markus Elfring
2016-12-12 17:56 ` Daniele Nicolodi
2016-12-12 18:03 ` Clarification for acceptance statistics? SF Markus Elfring
2016-12-12 21:02 ` Daniele Nicolodi
2016-12-12 22:11 ` SF Markus Elfring
2016-12-12 23:19 ` Daniele Nicolodi
2016-12-12 19:11 ` [media] bt8xx: One function call less in bttv_input_init() after error detection Dan Carpenter
2016-12-10 20:50 ` [PATCH 2/4] [media] bt8xx: Delete two error messages for a failed memory allocation SF Markus Elfring
2016-12-10 20:51 ` [PATCH 3/4] [media] bt8xx: Delete unnecessary variable initialisations in ca_send_message() SF Markus Elfring
2016-12-10 20:53 ` [PATCH 4/4] [media] bt8xx: Less function calls in dst_ca_ioctl() after error detection SF Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e20a6835-a404-e894-d0d0-a408bfcd7fb6@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=hans.verkuil@cisco.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=khoroshilov@ispras.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).