Skip to contentSkip to conversation

staging: otus: check kmalloc() return value

PATCH Superseded Kulikov Vasiliy 4 participants 4 messages Jul 30, 2010

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 3/9 staging: otus: check kmalloc() return value

kmalloc() may fail, if so return error from zfwUsbSubmitControl().

---
 drivers/staging/otus/wrap_usb.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/staging/otus/wrap_usb.c +5 -0
index 93459ca..9f04047 100644
@@ -104,6 +104,11 @@ u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index,
 
 	if (size > 0) {
 		buf = kmalloc(size, GFP_KERNEL);
+		if (buf = NULL) {
+			pr_err("zfwUsbSubmitControl() failed, "
+				  "kmalloc() returned NULL\n");
+			return 1;
+		}
 		memcpy(buf, (u8_t *)data, size);
 	} else
 		buf = NULL;
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 13 lines · Kulikov Vasiliy

kmalloc() may fail, if so return error from zfwUsbSubmitControl().

---
 drivers/staging/otus/wrap_usb.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/staging/otus/wrap_usb.c +0 -0
index 93459ca..9f04047 100644
@@ -104,6 +104,11 @@ u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index,
 

drivers/staging/otus/wrap_usb.c u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index, · line 114

Quoted 10 lines
drivers/staging/otus/wrap_usb.c +5 -0
 	if (size > 0) {
 		buf = kmalloc(size, GFP_KERNEL);
+		if (buf = NULL) {
+			pr_err("zfwUsbSubmitControl() failed, "
+				  "kmalloc() returned NULL\n");
+			return 1;
+		}
 		memcpy(buf, (u8_t *)data, size);
 	} else
 		buf = NULL;

We had a memdup() somewhere had'nt we ?

re,
wh

#2 lore raw
Quoted 16 lines · walter harms
Quoted 13 lines · Kulikov Vasiliy

kmalloc() may fail, if so return error from zfwUsbSubmitControl().

---
 drivers/staging/otus/wrap_usb.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/staging/otus/wrap_usb.c +0 -0
index 93459ca..9f04047 100644
@@ -104,6 +104,11 @@ u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index,
 
Quoted 13 lines

drivers/staging/otus/wrap_usb.c u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index, · line 114

Quoted 10 lines
drivers/staging/otus/wrap_usb.c +5 -0
 	if (size > 0) {
 		buf = kmalloc(size, GFP_KERNEL);
+		if (buf = NULL) {
+			pr_err("zfwUsbSubmitControl() failed, "
+				  "kmalloc() returned NULL\n");
+			return 1;
+		}
 		memcpy(buf, (u8_t *)data, size);
 	} else
 		buf = NULL;

We had a memdup() somewhere had'nt we ?

Yes, but it is not what he is changing. (Patches welcome.)

The patch is OK, except try to avoid function names in printks next time. Function names are constantly changing, but developers tend not to change printk strings. (%s + __func__)

regards,

Signature · 1 line
js
#3 lore raw
In reply to Kulikov Vasiliy

drivers/staging/otus/wrap_usb.c u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index, · line 109

Quoted 5 lines · Kulikov Vasiliy
drivers/staging/otus/wrap_usb.c +3 -0
 	if (size > 0) {
 		buf = kmalloc(size, GFP_KERNEL);
+		if (buf = NULL) {
+			pr_err("zfwUsbSubmitControl() failed, "
+				  "kmalloc() returned NULL\n");

This isn't a big deal, but the pr_err() isn't needed. kmalloc() already prints a message unless __GFP_NOWARN is used.

regards,
dan carpenter