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/char/vt.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff -puN drivers/char/vt.c~vt-honor-the-return-value-of-device_create_file drivers/char/vt.c --- a/drivers/char/vt.c~vt-honor-the-return-value-of-device_create_file +++ a/drivers/char/vt.c @@ -106,7 +106,8 @@ #define MAX_NR_CON_DRIVER 16 #define CON_DRIVER_FLAG_MODULE 1 -#define CON_DRIVER_FLAG_INIT 2 +#define CON_DRIVER_FLAG_INIT 2 +#define CON_DRIVER_FLAG_ATTR 4 struct con_driver { const struct consw *con; @@ -3071,21 +3072,39 @@ static struct device_attribute device_at static int vtconsole_init_device(struct con_driver *con) { - int i; + int i, error = 0; dev_set_drvdata(con->dev, con); - for (i = 0; i < ARRAY_SIZE(device_attrs); i++) - device_create_file(con->dev, &device_attrs[i]); - return 0; + con->flag |= CON_DRIVER_FLAG_ATTR; + + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { + error = device_create_file(con->dev, &device_attrs[i]); + + if (error) + break; + } + + if (error) { + while (--i >= 0) + device_remove_file(con->dev, &device_attrs[i]); + + con->flag &= ~CON_DRIVER_FLAG_ATTR; + } + + return error; } static void vtconsole_deinit_device(struct con_driver *con) { int i; - for (i = 0; i < ARRAY_SIZE(device_attrs); i++) - device_remove_file(con->dev, &device_attrs[i]); + if (con->flag & CON_DRIVER_FLAG_ATTR) { + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) + device_remove_file(con->dev, &device_attrs[i]); + + con->flag &= ~CON_DRIVER_FLAG_ATTR; + } } /** @@ -3183,6 +3202,7 @@ int register_con_driver(const struct con } else { vtconsole_init_device(con_driver); } + err: release_console_sem(); module_put(owner); _