Skip to contentSkip to conversation

fs/partitions/check.c: add error handling for kobject_add

PATCH In review Borislav Petkov 1 participant 2 messages Oct 22, 2007 – Oct 24, 2007 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/partitions/check.c: add error handling for kobject_add

From: Borislav Petkov <[email protected]>

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

--

fs/partitions/check.c +9 -2
index 722e12e..5490e33 100644
@@ -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");
Signature · 2 lines
Regards/Gruß,
    Boris.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 1 line · Andrew Morton

I get 100% rejects from this. Please redo against latest mainline.

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

---
From: Borislav Petkov <[email protected]>

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

--

fs/partitions/check.c +9 -2
index 722e12e..6ba66b4 100644
@@ -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");
Signature · 2 lines
Regards/Gruß,
    Boris.