Skip to contentSkip to conversation

drivers/usb/serial/mos7840.c: check

PATCH In review Amit Choudhary 3 participants 4 messages Oct 16, 2006 – Oct 18, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/usb/serial/mos7840.c: check

Description: Check the return value of kmalloc() in function mos7840_get_reg(), in file drivers/usb/serial/mos7840.c.

drivers/usb/serial/mos7840.c +8 -0
index 021be39..91d474b 100644
@@ -475,6 +475,14 @@ static int mos7840_get_reg(struct moschi
 	int ret = 0;
 	buffer = (__u8 *) mcs->ctrl_buf;
 
+	/* The memory for ctrl_buf is allocated in
+	 * mos7840_startup(), but it is not checked if
+	 * kmalloc failed. So, mcs->ctrl_buf might be NULL.
+	 * So, it should be checked here.
+	 */
+	if (!buffer)
+		return -ENOMEM;
+
 //      dr=(struct usb_ctrlrequest *)(buffer);
 	dr = (void *)(buffer + 2);
 	dr->bRequestType = MCS_RD_RTYPE;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw
Quoted 9 lines · Amit Choudhary

Description: Check the return value of kmalloc() in function mos7840_get_reg(), in file drivers/usb/serial/mos7840.c.

drivers/usb/serial/mos7840.c +0 -0
index 021be39..91d474b 100644

drivers/usb/serial/mos7840.c static int mos7840_get_reg(struct moschi · line 484

Quoted 10 lines
drivers/usb/serial/mos7840.c +7 -0
@@ -475,6 +475,14 @@ static int mos7840_get_reg(struct moschi
 	int ret = 0;
 	buffer = (__u8 *) mcs->ctrl_buf;
 
+	/* The memory for ctrl_buf is allocated in
+	 * mos7840_startup(), but it is not checked if
+	 * kmalloc failed. So, mcs->ctrl_buf might be NULL.
+	 * So, it should be checked here.
+	 */
+	if (!buffer)
+		return -ENOMEM;

Why not just check it in the startup function instead?

thanks,

greg k-h
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw
In reply to Amit Choudhary
Quoted 7 lines
Quoted 7 lines
drivers/usb/serial/mos7840.c +0 -0
@@ -475,6 +475,14 @@ static int mos7840_get_reg(struct moschi
 	int ret = 0;
 	buffer = (__u8 *) mcs->ctrl_buf;
 
Quoted 9 lines

drivers/usb/serial/mos7840.c static int mos7840_get_reg(struct moschi · line 484

Quoted 7 lines
drivers/usb/serial/mos7840.c +7 -0
+	/* The memory for ctrl_buf is allocated in
+	 * mos7840_startup(), but it is not checked if
+	 * kmalloc failed. So, mcs->ctrl_buf might be NULL.
+	 * So, it should be checked here.
+	 */
+	if (!buffer)
+		return -ENOMEM;

Why not just check it in the startup function instead?

After looking at the code, I inferred that it can still proceed if ctrl_buf is NULL because ctrl_buf is referenced only in mos7840_get_reg(). But please let me know if this is not the right way.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Kernel-janitors mailing list [email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#3 lore raw
In reply to Amit Choudhary
Quoted 17 lines · Amit Choudhary
Quoted 7 lines
Quoted 7 lines
drivers/usb/serial/mos7840.c +0 -0
@@ -475,6 +475,14 @@ static int mos7840_get_reg(struct moschi
 	int ret = 0;
 	buffer = (__u8 *) mcs->ctrl_buf;
 
Quoted 9 lines

drivers/usb/serial/mos7840.c static int mos7840_get_reg(struct moschi · line 484

Quoted 7 lines
drivers/usb/serial/mos7840.c +7 -0
+	/* The memory for ctrl_buf is allocated in
+	 * mos7840_startup(), but it is not checked if
+	 * kmalloc failed. So, mcs->ctrl_buf might be NULL.
+	 * So, it should be checked here.
+	 */
+	if (!buffer)
+		return -ENOMEM;

Why not just check it in the startup function instead?

Quoted 3 lines

After looking at the code, I inferred that it can still proceed if ctrl_buf is NULL because ctrl_buf is referenced only in mos7840_get_reg(). But please let me know if this is not the right way.

Nah, just error out in the beginning when the buffer is created. It makes is simpler to handle the low memory condition.

thanks,

greg k-h
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors