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

[PATCH] driver/base/memory.c: handle errors properly

Do proper error-checking and propagation in drivers/base/memory.c, hence fix
__must_check warnings.

Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Andrew Morton and committed by
Linus Torvalds
28ec24e2 0d75565f

+23 -11
+23 -11
drivers/base/memory.c
··· 290 290 291 291 static int block_size_init(void) 292 292 { 293 - sysfs_create_file(&memory_sysdev_class.kset.kobj, 294 - &class_attr_block_size_bytes.attr); 295 - return 0; 293 + return sysfs_create_file(&memory_sysdev_class.kset.kobj, 294 + &class_attr_block_size_bytes.attr); 296 295 } 297 296 298 297 /* ··· 322 323 323 324 static int memory_probe_init(void) 324 325 { 325 - sysfs_create_file(&memory_sysdev_class.kset.kobj, 326 - &class_attr_probe.attr); 327 - return 0; 326 + return sysfs_create_file(&memory_sysdev_class.kset.kobj, 327 + &class_attr_probe.attr); 328 328 } 329 329 #else 330 - #define memory_probe_init(...) do {} while (0) 330 + static inline int memory_probe_init(void) 331 + { 332 + return 0; 333 + } 331 334 #endif 332 335 333 336 /* ··· 432 431 { 433 432 unsigned int i; 434 433 int ret; 434 + int err; 435 435 436 436 memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops; 437 437 ret = sysdev_class_register(&memory_sysdev_class); 438 + if (ret) 439 + goto out; 438 440 439 441 /* 440 442 * Create entries for memory sections that were found ··· 446 442 for (i = 0; i < NR_MEM_SECTIONS; i++) { 447 443 if (!valid_section_nr(i)) 448 444 continue; 449 - add_memory_block(0, __nr_to_section(i), MEM_ONLINE, 0); 445 + err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE, 0); 446 + if (!ret) 447 + ret = err; 450 448 } 451 449 452 - memory_probe_init(); 453 - block_size_init(); 454 - 450 + err = memory_probe_init(); 451 + if (!ret) 452 + ret = err; 453 + err = block_size_init(); 454 + if (!ret) 455 + ret = err; 456 + out: 457 + if (ret) 458 + printk(KERN_ERR "%s() failed: %d\n", __FUNCTION__, ret); 455 459 return ret; 456 460 }