Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1661253 > unrolled thread

[PATCH v1 01/25] lib/vsprintf: Remove useless NULL checks

Started byAndy Shevchenko <andriy.shevchenko@linux.intel.com>
First post2017-06-08 16:00 +0200
Last post2017-06-08 23:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v1 01/25] lib/vsprintf: Remove useless NULL checks Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-06-08 16:00 +0200
    Re: [PATCH v1 01/25] lib/vsprintf: Remove useless NULL checks Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2017-06-08 23:00 +0200

#1661253 — [PATCH v1 01/25] lib/vsprintf: Remove useless NULL checks

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2017-06-08 16:00 +0200
Subject[PATCH v1 01/25] lib/vsprintf: Remove useless NULL checks
Message-ID<tQ68G-50i-5@gated-at.bofh.it>
The pointer can't be NULL since it's first what has been done in the
pointer().

Remove useless checks.

Note when we print clock name or rate it is safe in case !CONFIG_HAVE_CLK.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/vsprintf.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 9f16406288c0..031c2cc5c1c0 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -811,10 +811,6 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
 		/* nothing to print */
 		return buf;
 
-	if (ZERO_OR_NULL_PTR(addr))
-		/* NULL pointer */
-		return string(buf, end, NULL, spec);
-
 	switch (fmt[1]) {
 	case 'C':
 		separator = ':';
@@ -1253,10 +1249,6 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
 	if (spec.field_width == 0)
 		return buf;				/* nothing to print */
 
-	if (ZERO_OR_NULL_PTR(addr))
-		return string(buf, end, NULL, spec);	/* NULL pointer */
-
-
 	do {
 		switch (fmt[count++]) {
 		case 'a':
@@ -1391,9 +1383,6 @@ static noinline_for_stack
 char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
 	    const char *fmt)
 {
-	if (!IS_ENABLED(CONFIG_HAVE_CLK) || !clk)
-		return string(buf, end, NULL, spec);
-
 	switch (fmt[1]) {
 	case 'r':
 		return number(buf, end, clk_get_rate(clk), spec);
-- 
2.11.0

[toc] | [next] | [standalone]


#1661683

FromRasmus Villemoes <linux@rasmusvillemoes.dk>
Date2017-06-08 23:00 +0200
Message-ID<tQcH7-FJ-15@gated-at.bofh.it>
In reply to#1661253
On Thu, Jun 08 2017, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> The pointer can't be NULL since it's first what has been done in the
> pointer().
>
> Remove useless checks.
>
> Note when we print clock name or rate it is safe in case !CONFIG_HAVE_CLK.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  lib/vsprintf.c | 11 -----------
>  1 file changed, 11 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 9f16406288c0..031c2cc5c1c0 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -811,10 +811,6 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
>  		/* nothing to print */
>  		return buf;
>  
> -	if (ZERO_OR_NULL_PTR(addr))
> -		/* NULL pointer */
> -		return string(buf, end, NULL, spec);
> -
>  	switch (fmt[1]) {
>  	case 'C':
>  		separator = ':';
> @@ -1253,10 +1249,6 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
>  	if (spec.field_width == 0)
>  		return buf;				/* nothing to print */
>  
> -	if (ZERO_OR_NULL_PTR(addr))
> -		return string(buf, end, NULL, spec);	/* NULL pointer */
> -
> -

Well, ZERO_OR_NULL_PTR checks for a little more than !addr, but I
suppose that if anyone passes the result from kmalloc(0) to %ph, they'd
better also pass 0 as the size, so the .field_width tests should be
sufficient.

>  	do {
>  		switch (fmt[count++]) {
>  		case 'a':
> @@ -1391,9 +1383,6 @@ static noinline_for_stack
>  char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
>  	    const char *fmt)
>  {
> -	if (!IS_ENABLED(CONFIG_HAVE_CLK) || !clk)
> -		return string(buf, end, NULL, spec);
> -

Well, it may be safe, but removing the IS_ENABLED(CONFIG_HAVE_CLK) check
means that clock() becomes a much bigger function when
!IS_ENABLED(CONFIG_HAVE_CLK). You're right that the !clk check is
pointless.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web