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

hwmon: (w83627ehf) Use platform_create_bundle

Using platform_create_bundle() simplifies the module
init code and allows w83627ehf_probe() to be marked
as __init, lowering the runtime memory footprint.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20210709184501.6546-2-W_Armin@gmx.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Armin Wolf and committed by
Guenter Roeck
964c1c91 129cdce3

+10 -47
+10 -47
drivers/hwmon/w83627ehf.c
··· 1694 1694 .info = w83627ehf_info, 1695 1695 }; 1696 1696 1697 - static int w83627ehf_probe(struct platform_device *pdev) 1697 + static int __init w83627ehf_probe(struct platform_device *pdev) 1698 1698 { 1699 1699 struct device *dev = &pdev->dev; 1700 1700 struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev); ··· 2057 2057 .name = DRVNAME, 2058 2058 .pm = W83627EHF_DEV_PM_OPS, 2059 2059 }, 2060 - .probe = w83627ehf_probe, 2061 2060 .remove = w83627ehf_remove, 2062 2061 }; 2063 2062 ··· 2149 2150 /* 2150 2151 * when Super-I/O functions move to a separate file, the Super-I/O 2151 2152 * bus will manage the lifetime of the device and this module will only keep 2152 - * track of the w83627ehf driver. But since we platform_device_alloc(), we 2153 - * must keep track of the device 2153 + * track of the w83627ehf driver. 2154 2154 */ 2155 2155 static struct platform_device *pdev; 2156 2156 ··· 2157 2159 { 2158 2160 int err; 2159 2161 unsigned short address; 2160 - struct resource res; 2162 + struct resource res = { 2163 + .name = DRVNAME, 2164 + .flags = IORESOURCE_IO, 2165 + }; 2161 2166 struct w83627ehf_sio_data sio_data; 2162 2167 2163 2168 /* ··· 2174 2173 w83627ehf_find(0x4e, &address, &sio_data)) 2175 2174 return -ENODEV; 2176 2175 2177 - err = platform_driver_register(&w83627ehf_driver); 2178 - if (err) 2179 - goto exit; 2180 - 2181 - pdev = platform_device_alloc(DRVNAME, address); 2182 - if (!pdev) { 2183 - err = -ENOMEM; 2184 - pr_err("Device allocation failed\n"); 2185 - goto exit_unregister; 2186 - } 2187 - 2188 - err = platform_device_add_data(pdev, &sio_data, 2189 - sizeof(struct w83627ehf_sio_data)); 2190 - if (err) { 2191 - pr_err("Platform data allocation failed\n"); 2192 - goto exit_device_put; 2193 - } 2194 - 2195 - memset(&res, 0, sizeof(res)); 2196 - res.name = DRVNAME; 2197 2176 res.start = address + IOREGION_OFFSET; 2198 2177 res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; 2199 - res.flags = IORESOURCE_IO; 2200 2178 2201 2179 err = acpi_check_resource_conflict(&res); 2202 2180 if (err) 2203 - goto exit_device_put; 2181 + return err; 2204 2182 2205 - err = platform_device_add_resources(pdev, &res, 1); 2206 - if (err) { 2207 - pr_err("Device resource addition failed (%d)\n", err); 2208 - goto exit_device_put; 2209 - } 2183 + pdev = platform_create_bundle(&w83627ehf_driver, w83627ehf_probe, &res, 1, &sio_data, 2184 + sizeof(struct w83627ehf_sio_data)); 2210 2185 2211 - /* platform_device_add calls probe() */ 2212 - err = platform_device_add(pdev); 2213 - if (err) { 2214 - pr_err("Device addition failed (%d)\n", err); 2215 - goto exit_device_put; 2216 - } 2217 - 2218 - return 0; 2219 - 2220 - exit_device_put: 2221 - platform_device_put(pdev); 2222 - exit_unregister: 2223 - platform_driver_unregister(&w83627ehf_driver); 2224 - exit: 2225 - return err; 2186 + return PTR_ERR_OR_ZERO(pdev); 2226 2187 } 2227 2188 2228 2189 static void __exit sensors_w83627ehf_exit(void)