drivers/usb/serial/mos7840.c: check
Subsystems (3)
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
@@ -475,6 +475,14 @@ static int mos7840_get_reg(struct moschiint 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
Quoted 9 lines · Amit Choudhary
Description: Check the return value of
kmalloc()in functionmos7840_get_reg(), in filedrivers/usb/serial/mos7840.c.Signed-off-by Amit Choudhary <[email protected]>drivers/usb/serial/mos7840.c +0
-0
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 moschiint 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
Quoted 7 lines
Quoted 7 lines
drivers/usb/serial/mos7840.c +0
-0@@ -475,6 +475,14 @@ static int mos7840_get_reg(struct moschiint 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
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 moschiint 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_bufis NULL becausectrl_bufis referenced only inmos7840_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