aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug/shpchp_core.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/shpchp_core.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/shpchp_core.c')
-rw-r--r--drivers/pci/hotplug/shpchp_core.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 7414fd9ad1d2..b6de307248e4 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -99,22 +99,28 @@ static int init_slots(struct controller *ctrl)
99 struct hotplug_slot *hotplug_slot; 99 struct hotplug_slot *hotplug_slot;
100 struct hotplug_slot_info *info; 100 struct hotplug_slot_info *info;
101 char name[SLOT_NAME_SIZE]; 101 char name[SLOT_NAME_SIZE];
102 int retval = -ENOMEM; 102 int retval;
103 int i; 103 int i;
104 104
105 for (i = 0; i < ctrl->num_slots; i++) { 105 for (i = 0; i < ctrl->num_slots; i++) {
106 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 106 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
107 if (!slot) 107 if (!slot) {
108 retval = -ENOMEM;
108 goto error; 109 goto error;
110 }
109 111
110 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 112 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
111 if (!hotplug_slot) 113 if (!hotplug_slot) {
114 retval = -ENOMEM;
112 goto error_slot; 115 goto error_slot;
116 }
113 slot->hotplug_slot = hotplug_slot; 117 slot->hotplug_slot = hotplug_slot;
114 118
115 info = kzalloc(sizeof(*info), GFP_KERNEL); 119 info = kzalloc(sizeof(*info), GFP_KERNEL);
116 if (!info) 120 if (!info) {
121 retval = -ENOMEM;
117 goto error_hpslot; 122 goto error_hpslot;
123 }
118 hotplug_slot->info = info; 124 hotplug_slot->info = info;
119 125
120 slot->hp_slot = i; 126 slot->hp_slot = i;