staging: comedi: comedi_test: return error when comedi_test_init fails
PATCH 1/1 staging: comedi: comedi_test: return error when comedi_test_init fails
comedi_test_init() forgets to return error when it fails. Modify the return value to fix it.
--- drivers/staging/comedi/drivers/comedi_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/comedi/drivers/comedi_test.c +3 -1
@@ -799,12 +799,14 @@ static int __init comedi_test_init(void)if (!config_mode) { ctcls =class_create (THIS_MODULE ,CLASS_NAME );if (IS_ERR (ctcls)) { + ret =PTR_ERR (ctcls);pr_warn ("comedi_test: unable to create class\n" ); goto clean3; } ctdev =device_create (ctcls,NULL ,MKDEV (0 ,0 ),NULL ,DEV_NAME );if (IS_ERR (ctdev)) { + ret =PTR_ERR (ctdev);pr_warn ("comedi_test: unable to create device\n" ); goto clean2; }
@@ -826,7 +828,7 @@ static int __init comedi_test_init(void) clean3: ctcls =NULL ; -return 0 ; +return ret; }module_init (comedi_test_init);
Signature · 1 line
2.24.0
Quoted 30 lines · Chuhong Yuan
comedi_test_init()forgets to return error when it fails. Modify the return value to fix it.Fixes 9ff7400bd38c ("Staging: comedi: drivers: comedi_test: Add auto-configuration capability")Signed-off-by Chuhong Yuan <[email protected]>--- drivers/staging/comedi/drivers/comedi_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/staging/comedi/drivers/comedi_test.c +2
-0@@ -799,12 +799,14 @@ static int __init comedi_test_init(void)if (!config_mode) { ctcls =class_create (THIS_MODULE ,CLASS_NAME );if (IS_ERR (ctcls)) { + ret =PTR_ERR (ctcls);pr_warn ("comedi_test: unable to create class\n" ); goto clean3; } ctdev =device_create (ctcls,NULL ,MKDEV (0 ,0 ),NULL ,DEV_NAME );if (IS_ERR (ctdev)) { + ret =PTR_ERR (ctdev);pr_warn ("comedi_test: unable to create device\n" ); goto clean2; }
drivers/staging/comedi/drivers/comedi_test.c static int __init comedi_test_init(void) · line 834
Quoted 8 lines
drivers/staging/comedi/drivers/comedi_test.c +1
-1@@ -826,7 +828,7 @@ static int __init comedi_test_init(void) clean3: ctcls =NULL ; -return 0 ; +return ret; }module_init (comedi_test_init);
I suspect the current behaviour was by design because the module is not completely broken if it fails to create the "comedi_test" device. The module will just behave as if the "noauto" module parameter (which sets the 'config_mode' variable) was set to "true" if there is an error during class or device creation. That's probably why the kernel log messages are written with 'pr_warn()' rather than 'pr_err()'.
As long as the core "comedi" module has been loaded with the "comedi_num_legacy_minors" module parameter set to a non-zero value, it would still be possible to configure one of the "legacy" comedi devices to use the "comedi_test" driver via the COMEDI_DEVCONFIG ioctl.
However, returning an error might be preferable here, especially since the comedi core module's "comedi_num_legacy_minors" parameter defaults to zero.
I'm happy with the change of behaviour, but would suggest changing the 'pr_warn()' calls to 'pr_err()' to match this change.
Signature · 4 lines
-=( Ian Abbott <[email protected]> || Web: www.mev.co.uk )=- -=( MEV Ltd. is a company registered in England & Wales. )=- -=( Registered number: 02862268. Registered address: )=- -=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-