From: "Antonino A. Daplas" Check the return value of device_create_file(). If return is 'fail', remove attributes by calling device_remove_file(). Signed-off-by: Antonino Daplas Signed-off-by: Andrew Morton --- drivers/video/fbsysfs.c | 26 +++++++++++++++++++++----- include/linux/fb.h | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff -puN drivers/video/fbsysfs.c~fbdev-honor-the-return-value-of-device_create_file drivers/video/fbsysfs.c --- a/drivers/video/fbsysfs.c~fbdev-honor-the-return-value-of-device_create_file +++ a/drivers/video/fbsysfs.c @@ -20,6 +20,8 @@ #include #include +#define FB_SYSFS_FLAG_ATTR 1 + /** * framebuffer_alloc - creates a new frame buffer info structure * @@ -494,19 +496,33 @@ static struct device_attribute device_at int fb_init_device(struct fb_info *fb_info) { unsigned int i; + int error = 0; + dev_set_drvdata(fb_info->dev, fb_info); - for (i = 0; i < ARRAY_SIZE(device_attrs); i++) - device_create_file(fb_info->dev, &device_attrs[i]); - return 0; + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { + error = device_create_file(fb_info->dev, &device_attrs[i]); + if (error) + break; + } + + if (error) { + while (--i >= 0) + device_remove_file(fb_info->dev, &device_attrs[i]); + fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR; + } + return error; } void fb_cleanup_device(struct fb_info *fb_info) { unsigned int i; - for (i = 0; i < ARRAY_SIZE(device_attrs); i++) - device_remove_file(fb_info->dev, &device_attrs[i]); + if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) { + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) + device_remove_file(fb_info->dev, &device_attrs[i]); + fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR; + } } #ifdef CONFIG_FB_BACKLIGHT diff -puN include/linux/fb.h~fbdev-honor-the-return-value-of-device_create_file include/linux/fb.h --- a/include/linux/fb.h~fbdev-honor-the-return-value-of-device_create_file +++ a/include/linux/fb.h @@ -776,6 +776,7 @@ struct fb_info { struct fb_ops *fbops; struct device *parent; struct device *dev; /* sysfs per device attrs */ + int class_flag; /* private sysfs flags */ #ifdef CONFIG_FB_TILEBLITTING struct fb_tile_ops *tileops; /* Tile Blitting */ #endif _