smp: fix __smp_processor_id() backup macro

Message ID b12bdef9-d5c0-49cf-aea2-ff7b56220fdc@p183
State New
Headers
Series smp: fix __smp_processor_id() backup macro |

Commit Message

Alexey Dobriyan Oct. 14, 2023, 4:14 p.m. UTC
  Every __smp_processor_id usage doesn't have arguments and
every raw_smp_processor_id usage doesn't have arguments,
therefore "#define __smp_processor_id(x)" can not possibly work.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/linux/smp.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Andrew Morton Oct. 14, 2023, 10:12 p.m. UTC | #1
On Sat, 14 Oct 2023 19:14:15 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:

> Every __smp_processor_id usage doesn't have arguments and
> every raw_smp_processor_id usage doesn't have arguments,
> therefore "#define __smp_processor_id(x)" can not possibly work.
> 
> ...
>
> --- a/include/linux/smp.h
> +++ b/include/linux/smp.h
> @@ -261,7 +261,7 @@ static inline int get_boot_cpu_id(void)
>   * regular asm read for the stable.
>   */
>  #ifndef __smp_processor_id
> -#define __smp_processor_id(x) raw_smp_processor_id(x)
> +#define __smp_processor_id() raw_smp_processor_id()
>  #endif
>  

It's been that way for at least 4 years.  Presumably this is never used
and should be removed?
  
Alexey Dobriyan Oct. 15, 2023, 9:55 a.m. UTC | #2
On Sat, Oct 14, 2023 at 03:12:21PM -0700, Andrew Morton wrote:
> On Sat, 14 Oct 2023 19:14:15 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > Every __smp_processor_id usage doesn't have arguments and
> > every raw_smp_processor_id usage doesn't have arguments,
> > therefore "#define __smp_processor_id(x)" can not possibly work.
> > 
> > ...
> >
> > --- a/include/linux/smp.h
> > +++ b/include/linux/smp.h
> > @@ -261,7 +261,7 @@ static inline int get_boot_cpu_id(void)
> >   * regular asm read for the stable.
> >   */
> >  #ifndef __smp_processor_id
> > -#define __smp_processor_id(x) raw_smp_processor_id(x)
> > +#define __smp_processor_id() raw_smp_processor_id()
> >  #endif
> >  
> 
> It's been that way for at least 4 years.  Presumably this is never used
> and should be removed?

Deleting breaks compilation immediately.

C89 6.8.3 §4 says

	"The number of arguments in an invocation of a function-like
	macro shall agree with the number of parameters in the macro
	definition, ..."

C99 relaxes this in 6.10.3 §4

	the number of arguments (including those arguments
	consisting of no preprocesing tokens) ... shall equal
	the number of parameters in the macro definition.

So, "#define M()" works with M() only, but "#define M(a)" worked with
M(1) and started working as M() which is very funny.

In other words changelog is wrong: it can and does work (sort of by
accident).
  

Patch

--- a/include/linux/smp.h
+++ b/include/linux/smp.h
@@ -261,7 +261,7 @@  static inline int get_boot_cpu_id(void)
  * regular asm read for the stable.
  */
 #ifndef __smp_processor_id
-#define __smp_processor_id(x) raw_smp_processor_id(x)
+#define __smp_processor_id() raw_smp_processor_id()
 #endif
 
 #ifdef CONFIG_DEBUG_PREEMPT