diff mbox

compiler: Correct macro parameter expansion problem

Message ID 1415025253-15976-1-git-send-email-jeffrey.t.kirsher@intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Kirsher, Jeffrey T Nov. 3, 2014, 2:34 p.m. UTC
From: Mark Rustad <mark.d.rustad@intel.com>

The macro __compiletime_error_fallback has an error in that it
lacks parens around the expansion of an expression. It also
lacks a conversion to a boolean value. The first problem can
result in a mis-evaluation. The second problem can also result
in an error if the value comes out negative. That would thwart
the intended error generation. That is, the error being asserted
would not in fact generate an error. Fix both problems by adding
!!() to the expansion.

Signed-off-by: Mark Rustad <mark.d.rustad@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Josh Triplett Nov. 3, 2014, 2:48 p.m. UTC | #1
On Mon, Nov 03, 2014 at 06:34:13AM -0800, Jeff Kirsher wrote:
> From: Mark Rustad <mark.d.rustad@intel.com>
> 
> The macro __compiletime_error_fallback has an error in that it
> lacks parens around the expansion of an expression. It also
> lacks a conversion to a boolean value. The first problem can
> result in a mis-evaluation. The second problem can also result
> in an error if the value comes out negative. That would thwart
> the intended error generation. That is, the error being asserted
> would not in fact generate an error. Fix both problems by adding
> !!() to the expansion.
> 
> Signed-off-by: Mark Rustad <mark.d.rustad@intel.com>
> Tested-by: Aaron Brown <aaron.f.brown@intel.com>
> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>

Good catch.

Reviewed-by: Josh Triplett <josh@joshtriplett.org>

>  include/linux/compiler.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index d5ad7b1..59dc611 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -331,7 +331,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
>   */
>  # ifndef __CHECKER__
>  #  define __compiletime_error_fallback(condition) \
> -	do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
> +	do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
>  # endif
>  #endif
>  #ifndef __compiletime_error_fallback
> -- 
> 1.9.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d5ad7b1..59dc611 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -331,7 +331,7 @@  void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
  */
 # ifndef __CHECKER__
 #  define __compiletime_error_fallback(condition) \
-	do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
+	do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
 # endif
 #endif
 #ifndef __compiletime_error_fallback