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

Driver core: device_add_attrs() cleanup

Clean up the coding in device_add_attrs() a bit.

Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


authored by

Andrew Morton and committed by
Greg Kroah-Hartman
4aca67e5 873760fb

+10 -12
+10 -12
drivers/base/bus.c
··· 324 324 return error; 325 325 } 326 326 327 - static int device_add_attrs(struct bus_type * bus, struct device * dev) 327 + static int device_add_attrs(struct bus_type *bus, struct device *dev) 328 328 { 329 329 int error = 0; 330 330 int i; 331 331 332 - if (bus->dev_attrs) { 333 - for (i = 0; attr_name(bus->dev_attrs[i]); i++) { 334 - error = device_create_file(dev,&bus->dev_attrs[i]); 335 - if (error) 336 - goto Err; 332 + if (!bus->dev_attrs) 333 + return 0; 334 + 335 + for (i = 0; attr_name(bus->dev_attrs[i]); i++) { 336 + error = device_create_file(dev,&bus->dev_attrs[i]); 337 + if (error) { 338 + while (--i >= 0) 339 + device_remove_file(dev, &bus->dev_attrs[i]); 340 + break; 337 341 } 338 342 } 339 - Done: 340 343 return error; 341 - Err: 342 - while (--i >= 0) 343 - device_remove_file(dev,&bus->dev_attrs[i]); 344 - goto Done; 345 344 } 346 - 347 345 348 346 static void device_remove_attrs(struct bus_type * bus, struct device * dev) 349 347 {