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

[PATCH] md: remove unneeded NULL checks before kfree

This patch removes some unneeded checks of pointers being NULL before
calling kfree() on them. kfree() handles NULL pointers just fine, checking
first is pointless.

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Jesper Juhl and committed by
Linus Torvalds
990a8baf 8a5e9cf1

+17 -32
+1 -2
drivers/md/dm-crypt.c
··· 704 704 mempool_destroy(cc->page_pool); 705 705 mempool_destroy(cc->io_pool); 706 706 707 - if (cc->iv_mode) 708 - kfree(cc->iv_mode); 707 + kfree(cc->iv_mode); 709 708 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr) 710 709 cc->iv_gen_ops->dtr(cc); 711 710 crypto_free_tfm(cc->tfm);
+1 -2
drivers/md/linear.c
··· 217 217 return 0; 218 218 219 219 out: 220 - if (conf) 221 - kfree(conf); 220 + kfree(conf); 222 221 return 1; 223 222 } 224 223
+3 -7
drivers/md/md.c
··· 195 195 if (mddev->unit == unit) { 196 196 mddev_get(mddev); 197 197 spin_unlock(&all_mddevs_lock); 198 - if (new) 199 - kfree(new); 198 + kfree(new); 200 199 return mddev; 201 200 } 202 201 ··· 457 458 ret = 1; 458 459 459 460 abort: 460 - if (tmp1) 461 - kfree(tmp1); 462 - if (tmp2) 463 - kfree(tmp2); 464 - 461 + kfree(tmp1); 462 + kfree(tmp2); 465 463 return ret; 466 464 } 467 465
+1 -2
drivers/md/multipath.c
··· 533 533 out_free_conf: 534 534 if (conf->pool) 535 535 mempool_destroy(conf->pool); 536 - if (conf->multipaths) 537 - kfree(conf->multipaths); 536 + kfree(conf->multipaths); 538 537 kfree(conf); 539 538 mddev->private = NULL; 540 539 out:
+5 -7
drivers/md/raid0.c
··· 371 371 return 0; 372 372 373 373 out_free_conf: 374 - if (conf->strip_zone) 375 - kfree(conf->strip_zone); 376 - if (conf->devlist) 377 - kfree (conf->devlist); 374 + kfree(conf->strip_zone); 375 + kfree(conf->devlist); 378 376 kfree(conf); 379 377 mddev->private = NULL; 380 378 out: ··· 384 386 raid0_conf_t *conf = mddev_to_conf(mddev); 385 387 386 388 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ 387 - kfree (conf->hash_table); 389 + kfree(conf->hash_table); 388 390 conf->hash_table = NULL; 389 - kfree (conf->strip_zone); 391 + kfree(conf->strip_zone); 390 392 conf->strip_zone = NULL; 391 - kfree (conf); 393 + kfree(conf); 392 394 mddev->private = NULL; 393 395 394 396 return 0;
+4 -8
drivers/md/raid1.c
··· 1427 1427 if (conf) { 1428 1428 if (conf->r1bio_pool) 1429 1429 mempool_destroy(conf->r1bio_pool); 1430 - if (conf->mirrors) 1431 - kfree(conf->mirrors); 1432 - if (conf->poolinfo) 1433 - kfree(conf->poolinfo); 1430 + kfree(conf->mirrors); 1431 + kfree(conf->poolinfo); 1434 1432 kfree(conf); 1435 1433 mddev->private = NULL; 1436 1434 } ··· 1445 1447 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ 1446 1448 if (conf->r1bio_pool) 1447 1449 mempool_destroy(conf->r1bio_pool); 1448 - if (conf->mirrors) 1449 - kfree(conf->mirrors); 1450 - if (conf->poolinfo) 1451 - kfree(conf->poolinfo); 1450 + kfree(conf->mirrors); 1451 + kfree(conf->poolinfo); 1452 1452 kfree(conf); 1453 1453 mddev->private = NULL; 1454 1454 return 0;
+2 -4
drivers/md/raid10.c
··· 1737 1737 out_free_conf: 1738 1738 if (conf->r10bio_pool) 1739 1739 mempool_destroy(conf->r10bio_pool); 1740 - if (conf->mirrors) 1741 - kfree(conf->mirrors); 1740 + kfree(conf->mirrors); 1742 1741 kfree(conf); 1743 1742 mddev->private = NULL; 1744 1743 out: ··· 1753 1754 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ 1754 1755 if (conf->r10bio_pool) 1755 1756 mempool_destroy(conf->r10bio_pool); 1756 - if (conf->mirrors) 1757 - kfree(conf->mirrors); 1757 + kfree(conf->mirrors); 1758 1758 kfree(conf); 1759 1759 mddev->private = NULL; 1760 1760 return 0;