Skip to contentSkip to conversation

jz4740-adc/jz4740-hwmon: check kmalloc() result

PATCH Superseded Axel Lin 2 participants 2 messages Jul 29, 2010 – Aug 1, 2010

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 jz4740-adc/jz4740-hwmon: check kmalloc() result

If kmalloc() fails, exit with -ENOMEM.

---
This patch is against linux-next.

 drivers/hwmon/jz4740-hwmon.c |    4 ++++
 drivers/mfd/jz4740-adc.c     |    4 ++++
 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/hwmon/jz4740-hwmon.c +4 -0
index 72a4335..1c8b3d9 100644
@@ -107,6 +107,10 @@ static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
 	struct jz4740_hwmon *hwmon;
 
 	hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
+	if (!hwmon) {
+		dev_err(&pdev->dev, "Failed to allocate driver structure\n");
+		return -ENOMEM;
+	}
 
 	hwmon->cell = pdev->dev.platform_data;
 
drivers/mfd/jz4740-adc.c +4 -0
index 7a844ae..2846d24 100644
@@ -260,6 +260,10 @@ static int __devinit jz4740_adc_probe(struct platform_device *pdev)
 	int irq;
 
 	adc = kmalloc(sizeof(*adc), GFP_KERNEL);
+	if (!adc) {
+		dev_err(&pdev->dev, "Failed to allocate driver structure\n");
+		return -ENOMEM;
+	}
 
 	adc->irq = platform_get_irq(pdev, 0);
 	if (adc->irq < 0) {
Signature · 1 line
1.5.4.3
#1 lore raw

Hi Axel,

Quoted 1 line · Axel Lin

If kmalloc() fails, exit with -ENOMEM.

Could you please separate this patch in 2, as the 2 drivers live in different trees for now ?

Cheers,
Samuel.

Quoted 42 lines

---
This patch is against linux-next.

 drivers/hwmon/jz4740-hwmon.c |    4 ++++
 drivers/mfd/jz4740-adc.c     |    4 ++++
 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/hwmon/jz4740-hwmon.c +4 -0
index 72a4335..1c8b3d9 100644
@@ -107,6 +107,10 @@ static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
 	struct jz4740_hwmon *hwmon;
 
 	hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
+	if (!hwmon) {
+		dev_err(&pdev->dev, "Failed to allocate driver structure\n");
+		return -ENOMEM;
+	}
 
 	hwmon->cell = pdev->dev.platform_data;
 
drivers/mfd/jz4740-adc.c +4 -0
index 7a844ae..2846d24 100644
@@ -260,6 +260,10 @@ static int __devinit jz4740_adc_probe(struct platform_device *pdev)
 	int irq;
 
 	adc = kmalloc(sizeof(*adc), GFP_KERNEL);
+	if (!adc) {
+		dev_err(&pdev->dev, "Failed to allocate driver structure\n");
+		return -ENOMEM;
+	}
 
 	adc->irq = platform_get_irq(pdev, 0);
 	if (adc->irq < 0) {
Signature · 1 line
1.5.4.3
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/