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

TC: Error handling clean-ups

Rewrite TURBOchannel error handling to use a common failure path, making
sure put_device is called for devices that failed initialization. While
at it update printk calls to use pr_err rather than KERN_ERR.

Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/6701/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Maciej W. Rozycki and committed by
Ralf Baechle
e2afb7de 187c26dd

+19 -17
+19 -17
drivers/tc/tc.c
··· 83 83 /* Found a board, allocate it an entry in the list */ 84 84 tdev = kzalloc(sizeof(*tdev), GFP_KERNEL); 85 85 if (!tdev) { 86 - printk(KERN_ERR "tc%x: unable to allocate tc_dev\n", 87 - slot); 86 + pr_err("tc%x: unable to allocate tc_dev\n", slot); 88 87 goto out_err; 89 88 } 90 89 dev_set_name(&tdev->dev, "tc%x", slot); ··· 116 117 tdev->resource.start = extslotaddr; 117 118 tdev->resource.end = extslotaddr + devsize - 1; 118 119 } else { 119 - printk(KERN_ERR "%s: Cannot provide slot space " 120 - "(%dMiB required, up to %dMiB supported)\n", 121 - dev_name(&tdev->dev), devsize >> 20, 122 - max(slotsize, extslotsize) >> 20); 120 + pr_err("%s: Cannot provide slot space " 121 + "(%ldMiB required, up to %ldMiB supported)\n", 122 + dev_name(&tdev->dev), (long)(devsize >> 20), 123 + (long)(max(slotsize, extslotsize) >> 20)); 123 124 kfree(tdev); 124 125 goto out_err; 125 126 } ··· 146 147 { 147 148 /* Initialize the TURBOchannel bus */ 148 149 if (tc_bus_get_info(&tc_bus)) 149 - return 0; 150 + goto out_err; 150 151 151 152 INIT_LIST_HEAD(&tc_bus.devices); 152 153 dev_set_name(&tc_bus.dev, "tc"); 153 - if (device_register(&tc_bus.dev)) { 154 - put_device(&tc_bus.dev); 155 - return 0; 156 - } 154 + if (device_register(&tc_bus.dev)) 155 + goto out_err_device; 157 156 158 157 if (tc_bus.info.slot_size) { 159 158 unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000; ··· 169 172 tc_bus.resource[0].flags = IORESOURCE_MEM; 170 173 if (request_resource(&iomem_resource, 171 174 &tc_bus.resource[0]) < 0) { 172 - printk(KERN_ERR "tc: Cannot reserve resource\n"); 173 - return 0; 175 + pr_err("tc: Cannot reserve resource\n"); 176 + goto out_err_device; 174 177 } 175 178 if (tc_bus.ext_slot_size) { 176 179 tc_bus.resource[1].start = tc_bus.ext_slot_base; ··· 181 184 tc_bus.resource[1].flags = IORESOURCE_MEM; 182 185 if (request_resource(&iomem_resource, 183 186 &tc_bus.resource[1]) < 0) { 184 - printk(KERN_ERR 185 - "tc: Cannot reserve resource\n"); 186 - release_resource(&tc_bus.resource[0]); 187 - return 0; 187 + pr_err("tc: Cannot reserve resource\n"); 188 + goto out_err_resource; 188 189 } 189 190 } 190 191 191 192 tc_bus_add_devices(&tc_bus); 192 193 } 193 194 195 + return 0; 196 + 197 + out_err_resource: 198 + release_resource(&tc_bus.resource[0]); 199 + out_err_device: 200 + put_device(&tc_bus.dev); 201 + out_err: 194 202 return 0; 195 203 } 196 204