staging: dgrp: implement error handling in dgrp_create_class_sysfs_files()
There is no any error handling in dgrp_create_class_sysfs_files(). The patch adds code to check return values and propagate them to dgrp_init_module(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
70e90fb57f
commit
7e1389a9e6
|
@ -66,7 +66,7 @@ extern void dgrp_register_dpa_hook(struct proc_dir_entry *de);
|
||||||
extern void dgrp_dpa_data(struct nd_struct *, int, u8 *, int);
|
extern void dgrp_dpa_data(struct nd_struct *, int, u8 *, int);
|
||||||
|
|
||||||
/* from dgrp_sysfs.c */
|
/* from dgrp_sysfs.c */
|
||||||
extern void dgrp_create_class_sysfs_files(void);
|
extern int dgrp_create_class_sysfs_files(void);
|
||||||
extern void dgrp_remove_class_sysfs_files(void);
|
extern void dgrp_remove_class_sysfs_files(void);
|
||||||
|
|
||||||
extern void dgrp_create_node_class_sysfs_files(struct nd_struct *nd);
|
extern void dgrp_create_node_class_sysfs_files(struct nd_struct *nd);
|
||||||
|
|
|
@ -66,6 +66,8 @@ module_exit(dgrp_cleanup_module);
|
||||||
*/
|
*/
|
||||||
static int dgrp_init_module(void)
|
static int dgrp_init_module(void)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
INIT_LIST_HEAD(&nd_struct_list);
|
INIT_LIST_HEAD(&nd_struct_list);
|
||||||
|
|
||||||
spin_lock_init(&dgrp_poll_data.poll_lock);
|
spin_lock_init(&dgrp_poll_data.poll_lock);
|
||||||
|
@ -74,7 +76,9 @@ static int dgrp_init_module(void)
|
||||||
dgrp_poll_data.timer.function = dgrp_poll_handler;
|
dgrp_poll_data.timer.function = dgrp_poll_handler;
|
||||||
dgrp_poll_data.timer.data = (unsigned long) &dgrp_poll_data;
|
dgrp_poll_data.timer.data = (unsigned long) &dgrp_poll_data;
|
||||||
|
|
||||||
dgrp_create_class_sysfs_files();
|
ret = dgrp_create_class_sysfs_files();
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
dgrp_register_proc();
|
dgrp_register_proc();
|
||||||
|
|
||||||
|
|
|
@ -85,30 +85,50 @@ static struct attribute_group dgrp_global_settings_attribute_group = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void dgrp_create_class_sysfs_files(void)
|
int dgrp_create_class_sysfs_files(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int max_majors = 1U << (32 - MINORBITS);
|
int max_majors = 1U << (32 - MINORBITS);
|
||||||
|
|
||||||
dgrp_class = class_create(THIS_MODULE, "digi_realport");
|
dgrp_class = class_create(THIS_MODULE, "digi_realport");
|
||||||
|
if (IS_ERR(dgrp_class))
|
||||||
|
return PTR_ERR(dgrp_class);
|
||||||
ret = class_create_file(dgrp_class, &class_attr_driver_version);
|
ret = class_create_file(dgrp_class, &class_attr_driver_version);
|
||||||
|
if (ret)
|
||||||
|
goto err_class;
|
||||||
|
|
||||||
dgrp_class_global_settings_dev = device_create(dgrp_class, NULL,
|
dgrp_class_global_settings_dev = device_create(dgrp_class, NULL,
|
||||||
MKDEV(0, max_majors + 1), NULL, "driver_settings");
|
MKDEV(0, max_majors + 1), NULL, "driver_settings");
|
||||||
|
if (IS_ERR(dgrp_class_global_settings_dev)) {
|
||||||
|
ret = PTR_ERR(dgrp_class_global_settings_dev);
|
||||||
|
goto err_file;
|
||||||
|
}
|
||||||
ret = sysfs_create_group(&dgrp_class_global_settings_dev->kobj,
|
ret = sysfs_create_group(&dgrp_class_global_settings_dev->kobj,
|
||||||
&dgrp_global_settings_attribute_group);
|
&dgrp_global_settings_attribute_group);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_alert("%s: failed to create sysfs global settings device attributes.\n",
|
pr_alert("%s: failed to create sysfs global settings device attributes.\n",
|
||||||
__func__);
|
__func__);
|
||||||
sysfs_remove_group(&dgrp_class_global_settings_dev->kobj,
|
goto err_dev1;
|
||||||
&dgrp_global_settings_attribute_group);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dgrp_class_nodes_dev = device_create(dgrp_class, NULL,
|
dgrp_class_nodes_dev = device_create(dgrp_class, NULL,
|
||||||
MKDEV(0, max_majors + 2), NULL, "nodes");
|
MKDEV(0, max_majors + 2), NULL, "nodes");
|
||||||
|
if (IS_ERR(dgrp_class_nodes_dev)) {
|
||||||
|
ret = PTR_ERR(dgrp_class_nodes_dev);
|
||||||
|
goto err_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
err_group:
|
||||||
|
sysfs_remove_group(&dgrp_class_global_settings_dev->kobj,
|
||||||
|
&dgrp_global_settings_attribute_group);
|
||||||
|
err_dev1:
|
||||||
|
device_destroy(dgrp_class, MKDEV(0, max_majors + 1));
|
||||||
|
err_file:
|
||||||
|
class_remove_file(dgrp_class, &class_attr_driver_version);
|
||||||
|
err_class:
|
||||||
|
class_destroy(dgrp_class);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue