Re: [PATCH] fs/partitions/check.c: add error handling for kobject_add

Previous thread: [PATCH 2/2 -v2 resend] x86_64 EFI boot support: EFI boot document by Huang, Ying on Wednesday, October 24, 2007 - 2:32 am. (1 message)

Next thread: [PATCH] DMA: Correct invalid assumptions in the Kconfig text by Haavard Skinnemoen on Wednesday, October 24, 2007 - 2:38 am. (10 messages)
From: Borislav Petkov
Date: Wednesday, October 24, 2007 - 2:32 am

Here you go, this one is against today's 24-rc1.

---
From: Borislav Petkov <bbpetkov@yahoo.de>

Add error handling to the kobject_add()-call and signal (the even highly
		unlikely) error condition.

Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de>
--
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 722e12e..6ba66b4 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -371,11 +371,12 @@ void delete_partition(struct gendisk *disk, int part)
 void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags)
 {
 	struct hd_struct *p;
+	int err = -EINVAL;
 
 	p = kzalloc(sizeof(*p), GFP_KERNEL);
 	if (!p)
 		return;
-	
+
 	p->start_sect = start;
 	p->nr_sects = len;
 	p->partno = part;
@@ -390,7 +391,13 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len,
 	p->kobj.parent = &disk->kobj;
 	p->kobj.ktype = &ktype_part;
 	kobject_init(&p->kobj);
-	kobject_add(&p->kobj);
+
+	err = kobject_add(&p->kobj);
+	if (err) {
+		pr_err("%s: error adding %s to sysfs.\n", __FUNCTION__,
+				kobject_name(&p->kobj));
+	}
+
 	if (!disk->part_uevent_suppress)
 		kobject_uevent(&p->kobj, KOBJ_ADD);
 	sysfs_create_link(&p->kobj, &block_subsys.kobj, "subsystem");
-- 
Regards/Gruß,
    Boris.
-

Previous thread: [PATCH 2/2 -v2 resend] x86_64 EFI boot support: EFI boot document by Huang, Ying on Wednesday, October 24, 2007 - 2:32 am. (1 message)

Next thread: [PATCH] DMA: Correct invalid assumptions in the Kconfig text by Haavard Skinnemoen on Wednesday, October 24, 2007 - 2:38 am. (10 messages)