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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux