public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] staging-greybus: Fine-tuning for four functions
@ 2016-12-09 14:32 SF Markus Elfring
  2016-12-09 14:34 ` [PATCH 1/4] staging: greybus: camera: One function call less in gb_camera_configure_streams() after SF Markus Elfring
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: SF Markus Elfring @ 2016-12-09 14:32 UTC (permalink / raw)
  To: devel, Alex Elder, Greg Kroah-Hartman, Johan Hovold,
	Rui Miguel Silva
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 9 Dec 2016 15:25:35 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
  One function call less in gb_camera_configure_streams() after error detection
  light: Use kcalloc() in two functions
  Check return value of a kstrndup() call in gb_lights_light_config()
  Use kcalloc() in gb_power_supplies_setup()

 drivers/staging/greybus/camera.c       | 16 +++++++++-------
 drivers/staging/greybus/light.c        | 12 ++++++++----
 drivers/staging/greybus/power_supply.c |  7 +++----
 3 files changed, 20 insertions(+), 15 deletions(-)

-- 
2.11.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] staging: greybus: camera: One function call less in gb_camera_configure_streams() after
  2016-12-09 14:32 [PATCH 0/4] staging-greybus: Fine-tuning for four functions SF Markus Elfring
@ 2016-12-09 14:34 ` SF Markus Elfring
  2016-12-09 14:36 ` [PATCH 2/4] staging: greybus: light: Use kcalloc() in two functions SF Markus Elfring
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2016-12-09 14:34 UTC (permalink / raw)
  To: devel, Alex Elder, Greg Kroah-Hartman, Johan Hovold,
	Rui Miguel Silva
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 8 Dec 2016 18:25:13 +0100

The kfree() function was called in one case by the
gb_camera_configure_streams() function during error handling
even if the passed variable contained a null pointer.

This issue was detected by using the Coccinelle software.

Adjust a jump target according to the Linux coding style convention.

Fixes: 3265edaf0d70433699eece915fcca6509332c0e8 ("greybus: Add driver for the camera class protocol")

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/staging/greybus/camera.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c
index 1c5b41ae6774..4479caed81bd 100644
--- a/drivers/staging/greybus/camera.c
+++ b/drivers/staging/greybus/camera.c
@@ -537,14 +537,15 @@ static int gb_camera_configure_streams(struct gb_camera *gcam,
 		return -EINVAL;
 
 	req_size = sizeof(*req) + nstreams * sizeof(req->config[0]);
-	resp_size = sizeof(*resp) + nstreams * sizeof(resp->config[0]);
-
 	req = kmalloc(req_size, GFP_KERNEL);
-	resp = kmalloc(resp_size, GFP_KERNEL);
-	if (!req || !resp) {
-		kfree(req);
-		kfree(resp);
+	if (!req)
 		return -ENOMEM;
+
+	resp_size = sizeof(*resp) + nstreams * sizeof(resp->config[0]);
+	resp = kmalloc(resp_size, GFP_KERNEL);
+	if (!resp) {
+		ret = -ENOMEM;
+		goto free_request;
 	}
 
 	req->num_streams = nstreams;
@@ -647,8 +648,9 @@ static int gb_camera_configure_streams(struct gb_camera *gcam,
 
 done_skip_pm_put:
 	mutex_unlock(&gcam->mutex);
-	kfree(req);
 	kfree(resp);
+free_request:
+	kfree(req);
 	return ret;
 }
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] staging: greybus: light: Use kcalloc() in two functions
  2016-12-09 14:32 [PATCH 0/4] staging-greybus: Fine-tuning for four functions SF Markus Elfring
  2016-12-09 14:34 ` [PATCH 1/4] staging: greybus: camera: One function call less in gb_camera_configure_streams() after SF Markus Elfring
@ 2016-12-09 14:36 ` SF Markus Elfring
  2016-12-09 14:37 ` [PATCH 3/4] staging: greybus: light: Check return value of a kstrndup() call in gb_lights_light_conf SF Markus Elfring
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2016-12-09 14:36 UTC (permalink / raw)
  To: devel, Alex Elder, Greg Kroah-Hartman, Johan Hovold,
	Rui Miguel Silva
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 9 Dec 2016 13:46:25 +0100

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Fixes: 2870b52bae4c81823ffcb3ed2b0626fb39d64f48 ("greybus: lights: add lights implementation")

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/staging/greybus/light.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index 8dffd8a7e762..27bfc20eb9a5 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -1030,9 +1030,9 @@ static int gb_lights_light_config(struct gb_lights *glights, u8 id)
 
 	light->channels_count = conf.channel_count;
 	light->name = kstrndup(conf.name, NAMES_MAX, GFP_KERNEL);
-
-	light->channels = kzalloc(light->channels_count *
-				  sizeof(struct gb_channel), GFP_KERNEL);
+	light->channels = kcalloc(light->channels_count,
+				  sizeof(*light->channels),
+				  GFP_KERNEL);
 	if (!light->channels)
 		return -ENOMEM;
 
@@ -1168,8 +1168,9 @@ static int gb_lights_create_all(struct gb_lights *glights)
 	if (ret < 0)
 		goto out;
 
-	glights->lights = kzalloc(glights->lights_count *
-				  sizeof(struct gb_light), GFP_KERNEL);
+	glights->lights = kcalloc(glights->lights_count,
+				  sizeof(*glights->lights),
+				  GFP_KERNEL);
 	if (!glights->lights) {
 		ret = -ENOMEM;
 		goto out;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] staging: greybus: light: Check return value of a kstrndup() call in gb_lights_light_conf
  2016-12-09 14:32 [PATCH 0/4] staging-greybus: Fine-tuning for four functions SF Markus Elfring
  2016-12-09 14:34 ` [PATCH 1/4] staging: greybus: camera: One function call less in gb_camera_configure_streams() after SF Markus Elfring
  2016-12-09 14:36 ` [PATCH 2/4] staging: greybus: light: Use kcalloc() in two functions SF Markus Elfring
@ 2016-12-09 14:37 ` SF Markus Elfring
  2016-12-09 14:40 ` [PATCH 4/4] staging: greybus: power_supply: Use kcalloc() in gb_power_supplies_setup() SF Markus Elfring
  2016-12-09 14:53 ` [PATCH 0/4] staging-greybus: Fine-tuning for four functions Greg Kroah-Hartman
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2016-12-09 14:37 UTC (permalink / raw)
  To: devel, Alex Elder, Greg Kroah-Hartman, Johan Hovold,
	Rui Miguel Silva
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 9 Dec 2016 14:36:16 +0100

A return value was not checked after a call of the function "kstrndup".
This issue was detected by using the Coccinelle software.

Add a bit of exception handling.

Fixes: 2870b52bae4c81823ffcb3ed2b0626fb39d64f48 ("greybus: lights: add lights implementation")

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/staging/greybus/light.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index 27bfc20eb9a5..c9c377f40f56 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -1030,6 +1030,9 @@ static int gb_lights_light_config(struct gb_lights *glights, u8 id)
 
 	light->channels_count = conf.channel_count;
 	light->name = kstrndup(conf.name, NAMES_MAX, GFP_KERNEL);
+	if (!light->name)
+		return -ENOMEM;
+
 	light->channels = kcalloc(light->channels_count,
 				  sizeof(*light->channels),
 				  GFP_KERNEL);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] staging: greybus: power_supply: Use kcalloc() in gb_power_supplies_setup()
  2016-12-09 14:32 [PATCH 0/4] staging-greybus: Fine-tuning for four functions SF Markus Elfring
                   ` (2 preceding siblings ...)
  2016-12-09 14:37 ` [PATCH 3/4] staging: greybus: light: Check return value of a kstrndup() call in gb_lights_light_conf SF Markus Elfring
@ 2016-12-09 14:40 ` SF Markus Elfring
  2016-12-09 14:53 ` [PATCH 0/4] staging-greybus: Fine-tuning for four functions Greg Kroah-Hartman
  4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2016-12-09 14:40 UTC (permalink / raw)
  To: devel, Alex Elder, Greg Kroah-Hartman, Johan Hovold,
	Rui Miguel Silva
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 9 Dec 2016 15:04:24 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Fixes: ffe2e2487a388cf01ec44439346363aa8d654cd4 ("greybus: power_supply: rework and operation changes")

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/staging/greybus/power_supply.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/power_supply.c b/drivers/staging/greybus/power_supply.c
index e85c988b7034..19080c7f1491 100644
--- a/drivers/staging/greybus/power_supply.c
+++ b/drivers/staging/greybus/power_supply.c
@@ -944,10 +944,9 @@ static int gb_power_supplies_setup(struct gb_power_supplies *supplies)
 	if (ret < 0)
 		goto out;
 
-	supplies->supply = kzalloc(supplies->supplies_count *
-				     sizeof(struct gb_power_supply),
-				     GFP_KERNEL);
-
+	supplies->supply = kcalloc(supplies->supplies_count,
+				   sizeof(*supplies->supply),
+				   GFP_KERNEL);
 	if (!supplies->supply) {
 		ret = -ENOMEM;
 		goto out;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] staging-greybus: Fine-tuning for four functions
  2016-12-09 14:32 [PATCH 0/4] staging-greybus: Fine-tuning for four functions SF Markus Elfring
                   ` (3 preceding siblings ...)
  2016-12-09 14:40 ` [PATCH 4/4] staging: greybus: power_supply: Use kcalloc() in gb_power_supplies_setup() SF Markus Elfring
@ 2016-12-09 14:53 ` Greg Kroah-Hartman
  4 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2016-12-09 14:53 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: devel, Alex Elder, Johan Hovold, Rui Miguel Silva,
	kernel-janitors, LKML

On Fri, Dec 09, 2016 at 03:32:38PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 9 Dec 2016 15:25:35 +0100
> 
> A few update suggestions were taken into account
> from static source code analysis.

Again, nope, sorry, not going to even look at these...

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-09 14:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-09 14:32 [PATCH 0/4] staging-greybus: Fine-tuning for four functions SF Markus Elfring
2016-12-09 14:34 ` [PATCH 1/4] staging: greybus: camera: One function call less in gb_camera_configure_streams() after SF Markus Elfring
2016-12-09 14:36 ` [PATCH 2/4] staging: greybus: light: Use kcalloc() in two functions SF Markus Elfring
2016-12-09 14:37 ` [PATCH 3/4] staging: greybus: light: Check return value of a kstrndup() call in gb_lights_light_conf SF Markus Elfring
2016-12-09 14:40 ` [PATCH 4/4] staging: greybus: power_supply: Use kcalloc() in gb_power_supplies_setup() SF Markus Elfring
2016-12-09 14:53 ` [PATCH 0/4] staging-greybus: Fine-tuning for four functions Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox