public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [-mm3 PATCH] (Retry) Check the return value of kobject_add and etc.
@ 2007-04-01  7:32 Cong WANG
  2007-04-02 11:01 ` Cornelia Huck
  0 siblings, 1 reply; 18+ messages in thread
From: Cong WANG @ 2007-04-01  7:32 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton, viro

Since kobject_add, sysfs_create_link and sysfs_create_file are marked
as '__must_check', we must always check their return values.

Signed-off-by: Cong WANG <xiyou.wangcong@gmail.com>

---
--- linux-2.6.21-rc5-mm3/fs/partitions/check.c.orig	2007-03-30
21:35:45.000000000 +0800
+++ linux-2.6.21-rc5-mm3/fs/partitions/check.c	2007-03-30
21:49:53.000000000 +0800
@@ -385,10 +385,16 @@ void add_partition(struct gendisk *disk,
 	p->kobj.parent = &disk->kobj;
 	p->kobj.ktype = &ktype_part;
 	kobject_init(&p->kobj);
-	kobject_add(&p->kobj);
+	if (kobject_add(&p->kobj)) {
+		kfree(p);
+		return;
+	}
 	if (!disk->part_uevent_suppress)
 		kobject_uevent(&p->kobj, KOBJ_ADD);
-	sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem");
+	if (sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem")) {
+		kfree(p);
+		return;
+	}
 	if (flags & ADDPART_FLAG_WHOLEDISK) {
 		static struct attribute addpartattr = {
 			.name = "whole_disk",
@@ -396,7 +402,10 @@ void add_partition(struct gendisk *disk,
 			.owner = THIS_MODULE,
 		};

-		sysfs_create_file(&p->kobj, &addpartattr);
+		if (sysfs_create_file(&p->kobj, &addpartattr)) {
+			kfree(p);
+			return;
+		}
 	}
 	partition_sysfs_add_subdir(p);
 	disk->part[part-1] = p;

^ permalink raw reply	[flat|nested] 18+ messages in thread
* RE: [-mm3 PATCH] (Retry) Check the return value of kobject_add and etc.
@ 2007-04-01  8:22 Parag Warudkar
  2007-04-01 13:46 ` Parag Warudkar
  0 siblings, 1 reply; 18+ messages in thread
From: Parag Warudkar @ 2007-04-01  8:22 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: linux-kernel

>-	kobject_add(&p->kobj);
>+	if (kobject_add(&p->kobj)) {
>+		kfree(p);
>+		return;

Please add a printk warning before the return statement to log a
proper warning stating what happened, which file and line etc. That
way people can know why something did not work as expected and
hopefully do something about it.

Parag

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2007-04-11  9:22 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-01  7:32 [-mm3 PATCH] (Retry) Check the return value of kobject_add and etc Cong WANG
2007-04-02 11:01 ` Cornelia Huck
2007-04-05  4:54   ` WANG Cong
2007-04-05  9:11     ` Cornelia Huck
2007-04-05 14:44       ` WANG Cong
2007-04-05 15:05         ` Cornelia Huck
2007-04-05 15:27           ` WANG Cong
2007-04-05 16:00             ` Cornelia Huck
2007-04-06  2:53               ` WANG Cong
2007-04-10 12:31                 ` Cornelia Huck
2007-04-10 12:35                   ` [Patch -mm] kobject: kobject_add() reference leak Cornelia Huck
2007-04-10 14:08                   ` [-mm3 PATCH] (Retry) Check the return value of kobject_add and etc WANG Cong
2007-04-10 22:18                     ` Andrew Morton
2007-04-11  6:45                       ` WANG Cong
2007-04-11  7:19                         ` Andrew Morton
2007-04-11  9:24                       ` Cornelia Huck
  -- strict thread matches above, loose matches on Subject: below --
2007-04-01  8:22 Parag Warudkar
2007-04-01 13:46 ` Parag Warudkar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox