mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: tidspbridge: pmgr: dspapi.c:  Cleaning up uninitialized variable
@ 2014-06-03 22:23 Rickard Strandqvist
  2014-06-07 19:44 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Rickard Strandqvist @ 2014-06-03 22:23 UTC (permalink / raw)
  To: Omar Ramirez Luna, Greg Kroah-Hartman
  Cc: Rickard Strandqvist, Rashika Kheria, devel, linux-kernel

There is a risk that the variables will be used without being initialized.
Has also improved error handling, after an email proposal from Dan Carpenter.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/staging/tidspbridge/pmgr/dspapi.c |   64 ++++++++++++++---------------
 1 file changed, 31 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index b7d5c8c..c4ccf17 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -340,23 +340,23 @@ int api_init_complete2(void)
 u32 mgrwrap_enum_node_info(union trapped_args *args, void *pr_ctxt)
 {
 	u8 *pndb_props;
-	u32 num_nodes;
-	int status = 0;
+	u32 num_nodes = 0;
+	int status;
 	u32 size = args->args_mgr_enumnode_info.ndb_props_size;
 
 	if (size < sizeof(struct dsp_ndbprops))
 		return -EINVAL;
+	size = sizeof(struct dsp_ndbprops);
 
 	pndb_props = kmalloc(size, GFP_KERNEL);
 	if (pndb_props == NULL)
-		status = -ENOMEM;
+		return -ENOMEM;
+
+	status =
+	    mgr_enum_node_info(args->args_mgr_enumnode_info.node_id,
+			       (struct dsp_ndbprops *)pndb_props, size,
+			       &num_nodes);
 
-	if (!status) {
-		status =
-		    mgr_enum_node_info(args->args_mgr_enumnode_info.node_id,
-				       (struct dsp_ndbprops *)pndb_props, size,
-				       &num_nodes);
-	}
 	CP_TO_USR(args->args_mgr_enumnode_info.ndb_props, pndb_props, status,
 		  size);
 	CP_TO_USR(args->args_mgr_enumnode_info.num_nodes, &num_nodes, status,
@@ -372,24 +372,26 @@ u32 mgrwrap_enum_node_info(union trapped_args *args, void *pr_ctxt)
 u32 mgrwrap_enum_proc_info(union trapped_args *args, void *pr_ctxt)
 {
 	u8 *processor_info;
-	u8 num_procs;
-	int status = 0;
+	u8 num_procs = 0;
+	int status;
 	u32 size = args->args_mgr_enumproc_info.processor_info_size;
 
 	if (size < sizeof(struct dsp_processorinfo))
 		return -EINVAL;
 
-	processor_info = kmalloc(size, GFP_KERNEL);
+	if (size > sizeof(struct mgr_processorextinfo))
+		size = sizeof(struct mgr_processorextinfo);
+
+	processor_info = kzalloc(size, GFP_KERNEL);
 	if (processor_info == NULL)
-		status = -ENOMEM;
+		return -ENOMEM;
+
+	status =
+	    mgr_enum_processor_info(args->args_mgr_enumproc_info.
+				    processor_id,
+				    (struct dsp_processorinfo *)
+				    processor_info, size, &num_procs);
 
-	if (!status) {
-		status =
-		    mgr_enum_processor_info(args->args_mgr_enumproc_info.
-					    processor_id,
-					    (struct dsp_processorinfo *)
-					    processor_info, size, &num_procs);
-	}
 	CP_TO_USR(args->args_mgr_enumproc_info.processor_info, processor_info,
 		  status, size);
 	CP_TO_USR(args->args_mgr_enumproc_info.num_procs, &num_procs,
@@ -475,11 +477,11 @@ u32 mgrwrap_wait_for_bridge_events(union trapped_args *args, void *pr_ctxt)
 	int status = 0;
 	struct dsp_notification *anotifications[MAX_EVENTS];
 	struct dsp_notification notifications[MAX_EVENTS];
-	u32 index, i;
+	u32 index = 0, i;
 	u32 count = args->args_mgr_wait.count;
 
 	if (count > MAX_EVENTS)
-		status = -EINVAL;
+		return -EINVAL;
 
 	/* get the array of pointers to user structures */
 	CP_FM_USR(anotifications, args->args_mgr_wait.anotifications,
@@ -487,19 +489,15 @@ u32 mgrwrap_wait_for_bridge_events(union trapped_args *args, void *pr_ctxt)
 	/* get the events */
 	for (i = 0; i < count; i++) {
 		CP_FM_USR(&notifications[i], anotifications[i], status, 1);
-		if (status || !notifications[i].handle) {
-			status = -EINVAL;
-			break;
-		}
+		if (status || !notifications[i].handle)
+			return -EINVAL;
 		/* set the array of pointers to kernel structures */
 		anotifications[i] = &notifications[i];
 	}
-	if (!status) {
-		status = mgr_wait_for_bridge_events(anotifications, count,
-							 &index,
-							 args->args_mgr_wait.
-							 timeout);
-	}
+	status = mgr_wait_for_bridge_events(anotifications, count,
+						 &index,
+						 args->args_mgr_wait.
+						 timeout);
 	CP_TO_USR(args->args_mgr_wait.index, &index, status, 1);
 	return status;
 }
@@ -1755,7 +1753,7 @@ u32 strmwrap_register_notify(union trapped_args *args, void *pr_ctxt)
  */
 u32 strmwrap_select(union trapped_args *args, void *pr_ctxt)
 {
-	u32 mask;
+	u32 mask = 0;
 	struct strm_object *strm_tab[MAX_STREAMS];
 	int status = 0;
 	struct strm_res_object *strm_res;
-- 
1.7.10.4


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

* Re: [PATCH] staging: tidspbridge: pmgr: dspapi.c: Cleaning up uninitialized variable
  2014-06-03 22:23 [PATCH] staging: tidspbridge: pmgr: dspapi.c: Cleaning up uninitialized variable Rickard Strandqvist
@ 2014-06-07 19:44 ` Dan Carpenter
  2014-06-08  0:01   ` Rickard Strandqvist
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2014-06-07 19:44 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Omar Ramirez Luna, Greg Kroah-Hartman, devel, Rashika Kheria,
	linux-kernel

On Wed, Jun 04, 2014 at 12:23:39AM +0200, Rickard Strandqvist wrote:
> There is a risk that the variables will be used without being initialized.
> Has also improved error handling, after an email proposal from Dan Carpenter.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>

Looks ok.  This fixes some information leak bugs.  Thanks.

regards,
dan carpenter


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

* Re: [PATCH] staging: tidspbridge: pmgr: dspapi.c: Cleaning up uninitialized variable
  2014-06-07 19:44 ` Dan Carpenter
@ 2014-06-08  0:01   ` Rickard Strandqvist
  0 siblings, 0 replies; 3+ messages in thread
From: Rickard Strandqvist @ 2014-06-08  0:01 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Omar Ramirez Luna, Greg Kroah-Hartman, devel, Rashika Kheria,
	linux-kernel

Hi

Sure, no problem!

Glad I could help, and additionally with more than just a two-line fix
this time :-)

Best regards
Rickard Strandqvist


2014-06-07 21:44 GMT+02:00 Dan Carpenter <dan.carpenter@oracle.com>:
> On Wed, Jun 04, 2014 at 12:23:39AM +0200, Rickard Strandqvist wrote:
>> There is a risk that the variables will be used without being initialized.
>> Has also improved error handling, after an email proposal from Dan Carpenter.
>>
>> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
>
> Looks ok.  This fixes some information leak bugs.  Thanks.
>
> regards,
> dan carpenter
>

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

end of thread, other threads:[~2014-06-08  0:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-03 22:23 [PATCH] staging: tidspbridge: pmgr: dspapi.c: Cleaning up uninitialized variable Rickard Strandqvist
2014-06-07 19:44 ` Dan Carpenter
2014-06-08  0:01   ` Rickard Strandqvist

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

all inboxes | Powered by JetHome®