public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] kernel/sysctl.c: about the return value after fail call
@ 2013-08-20  3:37 Chen Gang
  2013-08-20  3:38 ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Chen Gang
  0 siblings, 1 reply; 6+ messages in thread
From: Chen Gang @ 2013-08-20  3:37 UTC (permalink / raw)
  To: Ingo Molnar, a.p.zijlstra@chello.nl, Mel Gorman, riel
  Cc: Andrew Morton, linux-kernel@vger.kernel.org

Patch 1 for bug fix: check return value after call proc_put_char() in
__do_proc_doulongvec_minmax()

Patch 2 for simplify code : Simplify code for C code readers.


Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/sysctl.c |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

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

* [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax()
  2013-08-20  3:37 [PATCH 0/2] kernel/sysctl.c: about the return value after fail call Chen Gang
@ 2013-08-20  3:38 ` Chen Gang
  2013-08-20  3:39   ` [PATCH 2/2] kernel/sysctl.c: simplify code for C code readers Chen Gang
  2013-08-20  5:09   ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Joe Perches
  0 siblings, 2 replies; 6+ messages in thread
From: Chen Gang @ 2013-08-20  3:38 UTC (permalink / raw)
  To: Ingo Molnar, a.p.zijlstra@chello.nl, Mel Gorman, riel
  Cc: Andrew Morton, linux-kernel@vger.kernel.org

Need check the return value of proc_put_char(), just like another have
done in __do_proc_doulongvec_minmax().

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/sysctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7822cd8..ee00986 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2214,8 +2214,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
 			*i = val;
 		} else {
 			val = convdiv * (*i) / convmul;
-			if (!first)
+			if (!first) {
 				err = proc_put_char(&buffer, &left, '\t');
+				if (err)
+					goto free;
+			}
 			err = proc_put_long(&buffer, &left, val, false);
 			if (err)
 				break;
-- 
1.7.7.6

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

* [PATCH 2/2] kernel/sysctl.c: simplify code for C code readers
  2013-08-20  3:38 ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Chen Gang
@ 2013-08-20  3:39   ` Chen Gang
  2013-08-20  5:09   ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Joe Perches
  1 sibling, 0 replies; 6+ messages in thread
From: Chen Gang @ 2013-08-20  3:39 UTC (permalink / raw)
  To: Ingo Molnar, a.p.zijlstra@chello.nl, Mel Gorman, riel
  Cc: Andrew Morton, linux-kernel@vger.kernel.org

In related functions, they have already had tag 'free', so use 'goto'
instead of 'break' to keep one (not multiple) style in each function.

Also remove useless checking 'err' code or move it to related 'if' code
block.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/sysctl.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index ee00986..c05e2cd 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1958,27 +1958,28 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
 					     proc_wspace_sep,
 					     sizeof(proc_wspace_sep), NULL);
 			if (err)
-				break;
+				goto free;
 			if (conv(&neg, &lval, i, 1, data)) {
 				err = -EINVAL;
-				break;
+				goto free;
 			}
 		} else {
 			if (conv(&neg, &lval, i, 0, data)) {
 				err = -EINVAL;
-				break;
+				goto free;
 			}
-			if (!first)
+			if (!first) {
 				err = proc_put_char(&buffer, &left, '\t');
-			if (err)
-				break;
+				if (err)
+					goto free;
+			}
 			err = proc_put_long(&buffer, &left, lval, neg);
 			if (err)
-				break;
+				goto free;
 		}
 	}
 
-	if (!write && !first && left && !err)
+	if (!write && !first && left)
 		err = proc_put_char(&buffer, &left, '\n');
 	if (write && !err && left)
 		left -= proc_skip_spaces(&kbuf);
@@ -2206,7 +2207,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
 					     proc_wspace_sep,
 					     sizeof(proc_wspace_sep), NULL);
 			if (err)
-				break;
+				goto free;
 			if (neg)
 				continue;
 			if ((min && val < *min) || (max && val > *max))
@@ -2221,11 +2222,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
 			}
 			err = proc_put_long(&buffer, &left, val, false);
 			if (err)
-				break;
+				goto free;
 		}
 	}
 
-	if (!write && !first && left && !err)
+	if (!write && !first && left)
 		err = proc_put_char(&buffer, &left, '\n');
 	if (write && !err)
 		left -= proc_skip_spaces(&kbuf);
@@ -2515,7 +2516,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
 			return -ENOMEM;
 		}
 		proc_skip_char(&kbuf, &left, '\n');
-		while (!err && left) {
+		while (left) {
 			unsigned long val_a, val_b;
 			bool neg;
 
-- 
1.7.7.6

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

* Re: [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax()
  2013-08-20  3:38 ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Chen Gang
  2013-08-20  3:39   ` [PATCH 2/2] kernel/sysctl.c: simplify code for C code readers Chen Gang
@ 2013-08-20  5:09   ` Joe Perches
  2013-08-20  5:17     ` Chen Gang
  1 sibling, 1 reply; 6+ messages in thread
From: Joe Perches @ 2013-08-20  5:09 UTC (permalink / raw)
  To: Chen Gang
  Cc: Ingo Molnar, a.p.zijlstra@chello.nl, Mel Gorman, riel,
	Andrew Morton, linux-kernel@vger.kernel.org

On Tue, 2013-08-20 at 11:38 +0800, Chen Gang wrote:
> Need check the return value of proc_put_char(), just like another have
> done in __do_proc_doulongvec_minmax().
> 
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
>  kernel/sysctl.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 7822cd8..ee00986 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2214,8 +2214,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
>  			*i = val;
>  		} else {
>  			val = convdiv * (*i) / convmul;
> -			if (!first)
> +			if (!first) {
>  				err = proc_put_char(&buffer, &left, '\t');
> +				if (err)
> +					goto free;
> +			}

I think you should use break and convert it in
to goto free in patch 2/2.

Otherwise, this style looks out of place.

>  			err = proc_put_long(&buffer, &left, val, false);
>  			if (err)
>  				break;




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

* Re: [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax()
  2013-08-20  5:09   ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Joe Perches
@ 2013-08-20  5:17     ` Chen Gang
  2013-09-03  5:16       ` [PATCH] " Chen Gang
  0 siblings, 1 reply; 6+ messages in thread
From: Chen Gang @ 2013-08-20  5:17 UTC (permalink / raw)
  To: Joe Perches
  Cc: Ingo Molnar, a.p.zijlstra@chello.nl, Mel Gorman, riel,
	Andrew Morton, linux-kernel@vger.kernel.org

On 08/20/2013 01:09 PM, Joe Perches wrote:
> On Tue, 2013-08-20 at 11:38 +0800, Chen Gang wrote:
>> Need check the return value of proc_put_char(), just like another have
>> done in __do_proc_doulongvec_minmax().
>>
>> Signed-off-by: Chen Gang <gang.chen@asianux.com>
>> ---
>>  kernel/sysctl.c |    5 ++++-
>>  1 files changed, 4 insertions(+), 1 deletions(-)
>>
>> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
>> index 7822cd8..ee00986 100644
>> --- a/kernel/sysctl.c
>> +++ b/kernel/sysctl.c
>> @@ -2214,8 +2214,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
>>  			*i = val;
>>  		} else {
>>  			val = convdiv * (*i) / convmul;
>> -			if (!first)
>> +			if (!first) {
>>  				err = proc_put_char(&buffer, &left, '\t');
>> +				if (err)
>> +					goto free;
>> +			}
> 
> I think you should use break and convert it in
> to goto free in patch 2/2.
> 
> Otherwise, this style looks out of place.
> 

Hmm... It sounds reasonable to me, if necessary, I will send patch v2
for them (no reply means not need send patch v2, this time).

Thanks.

>>  			err = proc_put_long(&buffer, &left, val, false);
>>  			if (err)
>>  				break;
> 
> 
> 
> 
> 


-- 
Chen Gang

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

* [PATCH] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax()
  2013-08-20  5:17     ` Chen Gang
@ 2013-09-03  5:16       ` Chen Gang
  0 siblings, 0 replies; 6+ messages in thread
From: Chen Gang @ 2013-09-03  5:16 UTC (permalink / raw)
  To: Joe Perches, Ingo Molnar, a.p.zijlstra@chello.nl, Mel Gorman,
	riel
  Cc: Andrew Morton, linux-kernel@vger.kernel.org

Need check the return value of proc_put_char(), just like another have
done in __do_proc_doulongvec_minmax().

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/sysctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index b2f06f3..7453418 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2214,8 +2214,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
 			*i = val;
 		} else {
 			val = convdiv * (*i) / convmul;
-			if (!first)
+			if (!first) {
 				err = proc_put_char(&buffer, &left, '\t');
+				if (err)
+					break;
+			}
 			err = proc_put_long(&buffer, &left, val, false);
 			if (err)
 				break;
-- 
1.7.7.6

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

end of thread, other threads:[~2013-09-03  5:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-20  3:37 [PATCH 0/2] kernel/sysctl.c: about the return value after fail call Chen Gang
2013-08-20  3:38 ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Chen Gang
2013-08-20  3:39   ` [PATCH 2/2] kernel/sysctl.c: simplify code for C code readers Chen Gang
2013-08-20  5:09   ` [PATCH 1/2] kernel/sysctl.c: check return value after call proc_put_char() in __do_proc_doulongvec_minmax() Joe Perches
2013-08-20  5:17     ` Chen Gang
2013-09-03  5:16       ` [PATCH] " Chen Gang

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