Skip to contentSkip to conversation

drivers: iio: industrialio-core: add check when kzalloc fails

PATCH In review Bharath Vedartham 4 participants 5 messages Jan 24, 2019 – Jan 27, 2019 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: iio: industrialio-core: add check when kzalloc fails

add code to handle the case when kzalloc fails to allocate memory to dev

---
 drivers/iio/industrialio-core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/industrialio-core.c +2 -0
index 4f5cd9f..93caa6b 100644
@@ -1475,6 +1475,8 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
 		}
 		dev_set_name(&dev->dev, "iio:device%d", dev->id);
 		INIT_LIST_HEAD(&dev->buffer_list);
+	} else {
+		return NULL;
 	}
 
 	return dev;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 13 lines · Bharath Vedartham

add code to handle the case when kzalloc fails to allocate memory to dev

---
 drivers/iio/industrialio-core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/industrialio-core.c +0 -0
index 4f5cd9f..93caa6b 100644

drivers/iio/industrialio-core.c struct iio_dev *iio_device_alloc(int sizeof_priv) · line 1479

Quoted 5 lines
drivers/iio/industrialio-core.c +2 -0
@@ -1475,6 +1475,8 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
                }
                dev_set_name(&dev->dev, "iio:device%d", dev->id);
                INIT_LIST_HEAD(&dev->buffer_list);
+       } else {
+               return NULL;

I'd argue that this is a bit redundant, because dev is NULL, the return below (return dev) will also return NULL.

Alex

Quoted 6 lines
drivers/iio/industrialio-core.c +0 -1
        }
 
        return dev;
--

2.7.4

#2 lore raw
Quoted 9 lines · Alexandru Ardelean
Quoted 8 lines · Bharath Vedartham

add code to handle the case when kzalloc fails to allocate memory to dev

---
 drivers/iio/industrialio-core.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 13 lines

drivers/iio/industrialio-core.c struct iio_dev *iio_device_alloc(int sizeof_priv) · line 1479

Quoted 10 lines
drivers/iio/industrialio-core.c +2 -0
index 4f5cd9f..93caa6b 100644
@@ -1475,6 +1475,8 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
                }
                dev_set_name(&dev->dev, "iio:device%d", dev->id);
                INIT_LIST_HEAD(&dev->buffer_list);
+       } else {
+               return NULL;

I'd argue that this is a bit redundant, because dev is NULL, the return below (return dev) will also return NULL.

+1

Also, subject title is incorrect.

Always use:

$ git log --oneline drivers/iio/industrialio-core.c

Use the most frequently tag/subject from the output of above command.

"iio: core: ...." would be fine.

Signature · 4 lines
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
#3 lore raw
Quoted 10 lines · Himanshu Jha
Quoted 9 lines · Alexandru Ardelean
Quoted 8 lines · Bharath Vedartham

add code to handle the case when kzalloc fails to allocate memory to dev

---
 drivers/iio/industrialio-core.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/iio/industrialio-core.c +0 -0
index 4f5cd9f..93caa6b 100644
@@ -1475,6 +1475,8 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
Quoted 8 lines

drivers/iio/industrialio-core.c struct iio_dev *iio_device_alloc(int sizeof_priv) · line 1479

Quoted 5 lines
drivers/iio/industrialio-core.c +2 -0
                }
                dev_set_name(&dev->dev, "iio:device%d", dev->id);
                INIT_LIST_HEAD(&dev->buffer_list);
+       } else {
+               return NULL;

I'd argue that this is a bit redundant, because dev is NULL, the return below (return dev) will also return NULL.

Agreed. I will read the code more carefully from next time. Thank you :)

Quoted 5 lines

+1

Also, subject title is incorrect.

Quoted 15 lines

Always use:

$ git log --oneline drivers/iio/industrialio-core.c

Use the most frequently tag/subject from the output of above command.

"iio: core: ...." would be fine.

Signature · 4 lines
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

Yes will do that from next time. I was of the understanding that this header was good enough.

Thank you,
Bharath

#4 lore raw
In reply to Bharath Vedartham

drivers/iio/industrialio-core.c struct iio_dev *iio_device_alloc(int sizeof_priv) · line 1482

Quoted 11 lines · Bharath Vedartham

add code to handle the case when kzalloc fails to allocate memory to dev

drivers/iio/industrialio-core.c +2 -0
 		dev_set_name(&dev->dev, "iio:device%d", dev->id);
 		INIT_LIST_HEAD(&dev->buffer_list);
+	} else {
+		return NULL;
 	}
 
 	return dev;

Not needed, as the 'if (dev)' statement fails, dev is already null.