Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/leds/leds-sunfire.c: fix sunfire_led_generic_probe() error handling

- return -ENOMEM if kzalloc fails, rather than the current -EINVAL

- fix a memory leak in the case of goto out_unregister_led_cdevs

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Axel Lin and committed by
Linus Torvalds
e179840b 19ab5cb8

+7 -5
+7 -5
drivers/leds/leds-sunfire.c
··· 127 127 struct led_type *types) 128 128 { 129 129 struct sunfire_drvdata *p; 130 - int i, err = -EINVAL; 130 + int i, err; 131 131 132 132 if (pdev->num_resources != 1) { 133 133 printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n", 134 134 pdev->num_resources); 135 + err = -EINVAL; 135 136 goto out; 136 137 } 137 138 138 139 p = kzalloc(sizeof(*p), GFP_KERNEL); 139 140 if (!p) { 140 141 printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n"); 142 + err = -ENOMEM; 141 143 goto out; 142 144 } 143 145 ··· 162 160 163 161 dev_set_drvdata(&pdev->dev, p); 164 162 165 - err = 0; 166 - out: 167 - return err; 163 + return 0; 168 164 169 165 out_unregister_led_cdevs: 170 166 for (i--; i >= 0; i--) 171 167 led_classdev_unregister(&p->leds[i].led_cdev); 172 - goto out; 168 + kfree(p); 169 + out: 170 + return err; 173 171 } 174 172 175 173 static int __devexit sunfire_led_generic_remove(struct platform_device *pdev)