stm class: dummy_stm: Fix error return code in dummy_stm_init()
Subsystems (3)
PATCH 1/1 stm class: dummy_stm: Fix error return code in dummy_stm_init()
Although 'ret' has been initialized to -ENOMEM, but it will be reassigned by the "ret = stm_register_device(...)" statement in the for loop. So that, the value of 'ret' is unknown when kasprintf() failed.
Fixes bcfdf8afdebe ("stm class: dummy_stm: Create multiple devices")
Reported-by Hulk Robot <[email protected]>
Signed-off-by Zhen Lei <[email protected]>
--- drivers/hwtracing/stm/dummy_stm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hwtracing/stm/dummy_stm.c +4 -2
@@ -68,7 +68,7 @@ static int dummy_stm_link(struct stm_data *data, unsigned int master,static int dummy_stm_init (void ) { -int i, ret = -ENOMEM ; +int i, ret;if (nr_dummies <0 || nr_dummies >DUMMY_STM_MAX )return -EINVAL ;
@@ -80,8 +80,10 @@ static int dummy_stm_init(void)for (i =0 ; i < nr_dummies; i++) { dummy_stm[i].name =kasprintf (GFP_KERNEL ,"dummy_stm.%d" , i); -if (!dummy_stm[i].name) +if (!dummy_stm[i].name) { + ret = -ENOMEM ; goto fail_unregister; + } dummy_stm[i].sw_start = master_min; dummy_stm[i].sw_end = master_max;
Signature · 1 line
2.25.1
Hi all:
Can someone review it? Although it is unlikely that the OOM will
occur during initialization, this is indeed a coding error.
Quoted 37 lines · Zhen Lei
Although 'ret' has been initialized to
-ENOMEM, but it will be reassigned by the "ret =stm_register_device(...)" statement in the for loop. So that, the value of 'ret' is unknown whenkasprintf()failed.Fixes bcfdf8afdebe ("stm class: dummy_stm: Create multiple devices")Reported-by Hulk Robot <[email protected]>Signed-off-by Zhen Lei <[email protected]>--- drivers/hwtracing/stm/dummy_stm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/hwtracing/stm/dummy_stm.c +4
-2@@ -68,7 +68,7 @@ static int dummy_stm_link(struct stm_data *data, unsigned int master,static int dummy_stm_init (void ) { -int i, ret = -ENOMEM ; +int i, ret;if (nr_dummies <0 || nr_dummies >DUMMY_STM_MAX )return -EINVAL ;@@ -80,8 +80,10 @@ static int dummy_stm_init(void)for (i =0 ; i < nr_dummies; i++) { dummy_stm[i].name =kasprintf (GFP_KERNEL ,"dummy_stm.%d" , i); -if (!dummy_stm[i].name) +if (!dummy_stm[i].name) { + ret = -ENOMEM ; goto fail_unregister; + } dummy_stm[i].sw_start = master_min; dummy_stm[i].sw_end = master_max;