aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2011-07-25 20:13:16 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:57:15 -0400
commite179840ba88c342d215631356cbfe4e62c9f175b (patch)
treec17a1c242a4b2bcbe825d8ef48aaa131791cfe85 /drivers
parent19ab5cb8fb14a44a4eb0b532ddc3658b055d84f9 (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/leds/leds-sunfire.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/leds/leds-sunfire.c b/drivers/leds/leds-sunfire.c
index ab6d18f5c39..1757396b20b 100644
--- a/drivers/leds/leds-sunfire.c
+++ b/drivers/leds/leds-sunfire.c
@@ -127,17 +127,19 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
127 struct led_type *types) 127 struct led_type *types)
128{ 128{
129 struct sunfire_drvdata *p; 129 struct sunfire_drvdata *p;
130 int i, err = -EINVAL; 130 int i, err;
131 131
132 if (pdev->num_resources != 1) { 132 if (pdev->num_resources != 1) {
133 printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n", 133 printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n",
134 pdev->num_resources); 134 pdev->num_resources);
135 err = -EINVAL;
135 goto out; 136 goto out;
136 } 137 }
137 138
138 p = kzalloc(sizeof(*p), GFP_KERNEL); 139 p = kzalloc(sizeof(*p), GFP_KERNEL);
139 if (!p) { 140 if (!p) {
140 printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n"); 141 printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n");
142 err = -ENOMEM;
141 goto out; 143 goto out;
142 } 144 }
143 145
@@ -160,14 +162,14 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
160 162
161 dev_set_drvdata(&pdev->dev, p); 163 dev_set_drvdata(&pdev->dev, p);
162 164
163 err = 0; 165 return 0;
164out:
165 return err;
166 166
167out_unregister_led_cdevs: 167out_unregister_led_cdevs:
168 for (i--; i >= 0; i--) 168 for (i--; i >= 0; i--)
169 led_classdev_unregister(&p->leds[i].led_cdev); 169 led_classdev_unregister(&p->leds[i].led_cdev);
170 goto out; 170 kfree(p);
171out:
172 return err;
171} 173}
172 174
173static int __devexit sunfire_led_generic_remove(struct platform_device *pdev) 175static int __devexit sunfire_led_generic_remove(struct platform_device *pdev)