block:Add proper error handling to the function, disk_add_events
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 28 lines · Nicholas Krause
This adds the proper required error checking to the function,
disk_add_eventsfor 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_filesby 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.Signed-off-by Nicholas Krause <[email protected]>--- block/genhd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)block/genhd.c +3
-2@@ -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]
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_eventsfor 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_filesby 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.Signed-off-by Nicholas Krause <[email protected]>--- block/genhd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)block/genhd.c +0
-0@@ -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
-2disk->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