Staging: speakup: kobjects: Return the error type to caller
PATCH 1/1 Staging: speakup: kobjects: Return the error type to caller
Inorder to notify the user that value is not successfuly set in sys entry, error should be returned from store function instead of count
--- drivers/staging/speakup/kobjects.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/speakup/kobjects.c +4 -1
@@ -640,7 +640,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, len =E_INC ; else len =E_SET ; -if (kstrtol (cp,10 , &value) ==0 ) + ret =kstrtol (cp,10 , &value); +if (!ret) ret =spk_set_num_var (value, param, len);else pr_warn ("overflow or parsing error has occurred" );
@@ -688,6 +689,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,if (ret == -ERESTART )pr_info ("%s reset to default value\n" , param->name); +else if (ret <0 ) +return ret;return count; }EXPORT_SYMBOL_GPL (spk_var_store);
Signature · 1 line
1.9.1
Quoted 13 lines · Saurabh Sengar
Inorder to notify the user that value is not successfuly set in sys entry, error should be returned from store function instead of count
Signed-off-by Saurabh Sengar <[email protected]>--- drivers/staging/speakup/kobjects.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/staging/speakup/kobjects.c +0
-0
drivers/staging/speakup/kobjects.c ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, · line 645
Quoted 7 lines
drivers/staging/speakup/kobjects.c +2
-1@@ -640,7 +640,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, len =E_INC ; else len =E_SET ; -if (kstrtol (cp,10 , &value) ==0 ) + ret =kstrtol (cp,10 , &value); +if (!ret) ret =spk_set_num_var (value, param, len);
Both kstrtol() and spk_set_num_var() return -ERANGE. The next lines expect that if we got -ERANGE, then it came from spk_set_num_var() so they print a wrong message.
drivers/staging/speakup/kobjects.c ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, · line 691
Quoted 6 lines
drivers/staging/speakup/kobjects.c +0
-0else pr_warn ("overflow or parsing error has occurred" );@@ -688,6 +689,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,if (ret == -ERESTART )pr_info ("%s reset to default value\n" , param->name);
Is this really true?
This function is so weird and broken. Please look at it some more and fix it harder with a mallet.
regards,
dan carpenter
Quoted 9 lines · Dan Carpenter
Quoted 8 lines · Saurabh Sengar
Inorder to notify the user that value is not successfuly set in sys entry, error should be returned from store function instead of count
Signed-off-by Saurabh Sengar <[email protected]>--- drivers/staging/speakup/kobjects.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 16 lines
drivers/staging/speakup/kobjects.c ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, · line 645
Quoted 12 lines
drivers/staging/speakup/kobjects.c +2
-1@@ -640,7 +640,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, len =E_INC ; else len =E_SET ; -if (kstrtol (cp,10 , &value) ==0 ) + ret =kstrtol (cp,10 , &value); +if (!ret) ret =spk_set_num_var (value, param, len);Both
kstrtol()andspk_set_num_var()return-ERANGE. The next lines expect that if we got-ERANGE, then it came fromspk_set_num_var()so they print a wrong message.
Yes I understand this.
And in case we got -ERANGE from spk_set_num_var, it is printing the error message.
I have tested this too by passing the out of range values to few parameters.
Quoted 9 lines
drivers/staging/speakup/kobjects.c ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, · line 691
Quoted 7 lines
drivers/staging/speakup/kobjects.c +0
-0else pr_warn ("overflow or parsing error has occurred" );@@ -688,6 +689,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,if (ret == -ERESTART )pr_info ("%s reset to default value\n" , param->name);Is this really true?
Sorry, I am not sure here what you mean here.
I have not implemented it.
Quoted 3 lines
This function is so weird and broken. Please look at it some more and fix it harder with a mallet.
You mean I broke it ?
I don't think so, I have tested the functionality before submitting the patch. If you mean that this function already not in good shape, I understand and agree with you.
Quoted 4 lines
regards,
dan carpenter
Quoted 6 lines · Saurabh Sengar
Quoted 6 lines
drivers/staging/speakup/kobjects.c ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, · line 691
Quoted 4 lines
drivers/staging/speakup/kobjects.c +0
-0@@ -688,6 +689,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,if (ret == -ERESTART )pr_info ("%s reset to default value\n" , param->name);Is this really true?
Quoted 6 lines
Sorry, I am not sure here what you mean here.
I have not implemented it.Quoted 3 lines
This function is so weird and broken. Please look at it some more and fix it harder with a mallet.
You mean I broke it ?
No, I mean it was broken to begin with. Write a more extensive patch to fix it.
That printk should be moved up to where we actually do the reset. Anyway speakup is actually really bad and there is a lot of broken stuff so you don't have to fix this function if you don't want to. Just fix the -ERANGE issue I mentioned and resend if you want.
regards,
dan carpenter
PATCH v2 1/1 Staging: speakup: kobjects: Return the error type to caller
Inorder to notify the user that value is not successfuly set in sys entry, error should be returned from store function instead of count
---
v2:
Hi Dan,
I will look more into this function in my free time. For now just sending you this patch fixing ERANGE as commented
drivers/staging/speakup/kobjects.c | 4 +++- drivers/staging/staging.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/staging/speakup/kobjects.c +3 -1
@@ -640,7 +640,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, len =E_INC ; else len =E_SET ; -if (kstrtol (cp,10 , &value) ==0 ) +if (!kstrtol (cp,10 , &value)) ret =spk_set_num_var (value, param, len);else pr_warn ("overflow or parsing error has occurred" );
@@ -688,6 +688,8 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,if (ret == -ERESTART )pr_info ("%s reset to default value\n" , param->name); +else if (ret <0 ) +return ret;return count; }EXPORT_SYMBOL_GPL (spk_var_store);
drivers/staging/staging.c +2 -2
@@ -2,12 +2,12 @@#include <linux/init.h> #include <linux/module.h> -static int __init staging_init (void ) +static int staging_init (void ) {return 0 ; } -static void __exit staging_exit(void) +static void staging_exit (void ) { }
Signature · 1 line
1.9.1