aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug/pcihp_skeleton.c
diff options
context:
space:
mode:
authorJulia Lawall <Julia.Lawall@lip6.fr>2012-07-16 11:25:56 -0400
committerBjorn Helgaas <bhelgaas@google.com>2012-07-16 11:25:56 -0400
commit83d057107382b74a4b15c59971631aa3542599a5 (patch)
treec9a5a3f79af2ff06c466bfff79dc816107f5ff2e /drivers/pci/hotplug/pcihp_skeleton.c
parentcfaf025112d3856637ff34a767ef785ef5cf2ca9 (diff)
PCI: hotplug: ensure a consistent return value in error case
Typically, the return value desired for the failure of a function with an integer return value is a negative integer. In these cases, the return value is sometimes a negative integer and sometimes 0, due to a subsequent initialization of the return variable within the loop. A simplified version of the semantic match that finds this problem is: (http://coccinelle.lip6.fr/) //<smpl> @r exists@ identifier ret; position p; constant C; expression e1,e3,e4; statement S; @@ ret = -C ... when != ret = e3 when any if@p (...) S ... when any if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; } ... when != ret = e3 when any *if@p (...) { ... when != ret = e4 return ret; } //</smpl> [bhelgaas: squashed into one patch] Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/hotplug/pcihp_skeleton.c')
-rw-r--r--drivers/pci/hotplug/pcihp_skeleton.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/pci/hotplug/pcihp_skeleton.c b/drivers/pci/hotplug/pcihp_skeleton.c
index b20ceaaa31f4..1f00b937f721 100644
--- a/drivers/pci/hotplug/pcihp_skeleton.c
+++ b/drivers/pci/hotplug/pcihp_skeleton.c
@@ -252,7 +252,7 @@ static int __init init_slots(void)
252 struct slot *slot; 252 struct slot *slot;
253 struct hotplug_slot *hotplug_slot; 253 struct hotplug_slot *hotplug_slot;
254 struct hotplug_slot_info *info; 254 struct hotplug_slot_info *info;
255 int retval = -ENOMEM; 255 int retval;
256 int i; 256 int i;
257 257
258 /* 258 /*
@@ -261,17 +261,23 @@ static int __init init_slots(void)
261 */ 261 */
262 for (i = 0; i < num_slots; ++i) { 262 for (i = 0; i < num_slots; ++i) {
263 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 263 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
264 if (!slot) 264 if (!slot) {
265 retval = -ENOMEM;
265 goto error; 266 goto error;
267 }
266 268
267 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 269 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
268 if (!hotplug_slot) 270 if (!hotplug_slot) {
271 retval = -ENOMEM;
269 goto error_slot; 272 goto error_slot;
273 }
270 slot->hotplug_slot = hotplug_slot; 274 slot->hotplug_slot = hotplug_slot;
271 275
272 info = kzalloc(sizeof(*info), GFP_KERNEL); 276 info = kzalloc(sizeof(*info), GFP_KERNEL);
273 if (!info) 277 if (!info) {
278 retval = -ENOMEM;
274 goto error_hpslot; 279 goto error_hpslot;
280 }
275 hotplug_slot->info = info; 281 hotplug_slot->info = info;
276 282
277 slot->number = i; 283 slot->number = i;