Skip to contentSkip to conversation

block:Add proper error handling to the function, disk_add_events

PATCH Jens Axboe 1 participant 2 messages May 15, 2015 2 messages not in the archive

lore
Share & tools
lore

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

Jens Axboe

author
#1 lore raw
Quoted 28 lines · Nicholas Krause

This adds the proper required error checking to the function, disk_add_events for when there are no disk events by returning the error code, -EBUSY. Further this also adds error checking for when our call to the function, sysfs_create_files by making this function's return now go into a newly declared variable, ret and at the end of this function's body return it to indicate whether this function is successful or not to the caller.

---
  block/genhd.c | 13 +++++++++----
  1 file changed, 9 insertions(+), 4 deletions(-)
block/genhd.c +3 -2
index 0a536dc..3eb7ee9 100644
@@ -1803,15 +1803,19 @@ static void disk_alloc_events(struct gendisk *disk)
  	disk->ev = ev;
  }
 
-static void disk_add_events(struct gendisk *disk)
+static int disk_add_events(struct gendisk *disk)
  {
+	int ret = 0;
  	if (!disk->ev)
-		return;
+		return -EBUSY;

block/genhd.c static void disk_alloc_events(struct gendisk *disk) · line 1818

Quoted 10 lines
block/genhd.c +5 -2
+
+	ret = sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs)
 
-	/* FIXME: error handling */
-	if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0)
+	if (!ret) {
  		pr_warn("%s: failed to create sysfs files for events\n",
  			disk->disk_name);
+		return ret;
+	}

You didn't even test this, obviously.

Signature · 1 line
Jens Axboe

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

author
#3 lore raw
Quoted 40 lines · Nicholas Krause
Quoted 37 lines · Jens Axboe

block/genhd.c static void disk_alloc_events(struct gendisk

Quoted 18 lines · Nicholas Krause

This adds the proper required error checking to the function, disk_add_events for when there are no disk events by returning the error code, -EBUSY. Further this also adds error checking for when our call to the function, sysfs_create_files by making this function's return now go into a newly declared variable, ret and at the end of this function's body return it to indicate whether this function is successful or not to the caller.

---
   block/genhd.c | 13 +++++++++----
   1 file changed, 9 insertions(+), 4 deletions(-)
block/genhd.c +0 -0
index 0a536dc..3eb7ee9 100644
@@ -1803,15 +1803,19 @@ static void disk_alloc_events(struct gendisk

*disk)

block/genhd.c static void disk_alloc_events(struct gendisk · line 1812

Quoted 12 lines
block/genhd.c +5 -2
   	disk->ev = ev;
   }
 
-static void disk_add_events(struct gendisk *disk)
+static int disk_add_events(struct gendisk *disk)
   {
+	int ret = 0;
   	if (!disk->ev)
-		return;
+		return -EBUSY;
+
+	ret = sysfs_create_files(&disk_to_dev(disk)->kobj,

disk_events_attrs)

block/genhd.c static void disk_alloc_events(struct gendisk · line 1811

Quoted 3 lines
block/genhd.c +0 -2
-	/* FIXME: error handling */
-	if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs)

< 0)

Quoted 8 lines
Quoted 7 lines

block/genhd.c static void disk_alloc_events(struct gendisk · line 1817

Quoted 5 lines
block/genhd.c +3 -0
+	if (!ret) {
   		pr_warn("%s: failed to create sysfs files for events\n",
   			disk->disk_name);
+		return ret;
+	}

You didn't even test this, obviously.

It builds on my system. I can't see anything wrong with it, please explain.

The fact that it compiles does not constitute that it has been tested. And it's definitely broken, as a test boot would have revealed.

Signature · 1 line
Jens Axboe