public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: speakup: kobjects: Return the error type to caller
@ 2015-12-04 14:42 Saurabh Sengar
  2015-12-07  6:48 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Saurabh Sengar @ 2015-12-04 14:42 UTC (permalink / raw)
  To: w.d.hubbs, chris, kirk, samuel.thibault, gregkh, speakup, devel,
	linux-kernel
  Cc: 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 <saurabh.truth@gmail.com>
---
 drivers/staging/speakup/kobjects.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index fdfeb42..b3a83fb 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -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);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Staging: speakup: kobjects: Return the error type to caller
  2015-12-04 14:42 [PATCH] Staging: speakup: kobjects: Return the error type to caller Saurabh Sengar
@ 2015-12-07  6:48 ` Dan Carpenter
  2015-12-07  7:16   ` Saurabh Sengar
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2015-12-07  6:48 UTC (permalink / raw)
  To: Saurabh Sengar
  Cc: w.d.hubbs, chris, kirk, samuel.thibault, gregkh, speakup, devel,
	linux-kernel

On Fri, Dec 04, 2015 at 08:12:33PM +0530, Saurabh Sengar wrote:
> 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 <saurabh.truth@gmail.com>
> ---
>  drivers/staging/speakup/kobjects.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
> index fdfeb42..b3a83fb 100644
> --- a/drivers/staging/speakup/kobjects.c
> +++ b/drivers/staging/speakup/kobjects.c
> @@ -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.

>  		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);

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Staging: speakup: kobjects: Return the error type to caller
  2015-12-07  6:48 ` Dan Carpenter
@ 2015-12-07  7:16   ` Saurabh Sengar
  2015-12-07  8:31     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Saurabh Sengar @ 2015-12-07  7:16 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: William Hubbs, Christopher Brannon, kirk, Samuel Thibault,
	Greg KH, speakup, devel, linux-kernel

On 7 December 2015 at 12:18, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> On Fri, Dec 04, 2015 at 08:12:33PM +0530, Saurabh Sengar wrote:
>> 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 <saurabh.truth@gmail.com>
>> ---
>>  drivers/staging/speakup/kobjects.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
>> index fdfeb42..b3a83fb 100644
>> --- a/drivers/staging/speakup/kobjects.c
>> +++ b/drivers/staging/speakup/kobjects.c
>> @@ -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.

 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.

>
>>               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);
>
> Is this really true?
Sorry, I am not sure here what you mean here.
I have not implemented it.
>
> 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.
>
> regards,
> dan carpenter
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Staging: speakup: kobjects: Return the error type to caller
  2015-12-07  7:16   ` Saurabh Sengar
@ 2015-12-07  8:31     ` Dan Carpenter
  2015-12-07  9:59       ` [PATCH v2] " Saurabh Sengar
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2015-12-07  8:31 UTC (permalink / raw)
  To: Saurabh Sengar
  Cc: devel, kirk, Greg KH, speakup, linux-kernel, Samuel Thibault,
	Christopher Brannon

On Mon, Dec 07, 2015 at 12:46:37PM +0530, Saurabh Sengar wrote:
> >> @@ -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.
> >
> > 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] Staging: speakup: kobjects: Return the error type to caller
  2015-12-07  8:31     ` Dan Carpenter
@ 2015-12-07  9:59       ` Saurabh Sengar
  0 siblings, 0 replies; 5+ messages in thread
From: Saurabh Sengar @ 2015-12-07  9:59 UTC (permalink / raw)
  To: dan.carpenter, devel, kirk, gregkh, speakup, linux-kernel,
	samuel.thibault, chris
  Cc: 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 <saurabh.truth@gmail.com>
---
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(-)

diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index fdfeb42..509163c 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -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);
diff --git a/drivers/staging/staging.c b/drivers/staging/staging.c
index 233e589..36dd594 100644
--- a/drivers/staging/staging.c
+++ b/drivers/staging/staging.c
@@ -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)
 {
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-07 10:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-04 14:42 [PATCH] Staging: speakup: kobjects: Return the error type to caller Saurabh Sengar
2015-12-07  6:48 ` Dan Carpenter
2015-12-07  7:16   ` Saurabh Sengar
2015-12-07  8:31     ` Dan Carpenter
2015-12-07  9:59       ` [PATCH v2] " Saurabh Sengar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox