[Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

Lucas De Marchi lucas.demarchi at intel.com
Wed Nov 25 19:52:15 UTC 2020


On Wed, Nov 25, 2020 at 11:30:44AM -0800, Aditya Swarup wrote:
>> As I said in the other reply, sizeof does actually work here:
>
>The question is not about sizeof() not working but rather the usage of ARRAY_SIZE()
>macro in i915_drv.h with just extern declaration without size specified.

ARRAY_SIZE() is just sizeof(arr)/sizeof(*arr) with additional
shenanigans to check for misuse: when used with a pointer rather than an
array:

	int b[0];
	int *a = b;

	or

	void foo(int a[10])

In these cases 	ARRAY_SIZE(a) will not do what you expect and the macro
warns about it, because sizeof(a) will be sizeof(int *) instead of the
array size.


>
>>
>>     $ cat /tmp/a.c
>>     #include <stdio.h>
>>
>>     #include "b.h"
>>
>>     int main(int argc, const char *argv[])
>>     {
>>         printf("%zu", sizeof(tgl_uy_revids));
>>         return 0;
>>     }
>>
>>     $ cat /tmp/b.h
>>     #pragma once
>>
>>     struct i915_rev_steppings { int a; };
>>     extern const struct i915_rev_steppings tgl_uy_revids[4];
>
>You are specifying the size in the extern declaration which will make the ARRAY_SIZE()
>macro work if used in the header else it will complain.

as it should

Lucas De Marchi


More information about the Intel-gfx mailing list