[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8394dbcd-f500-b1ae-fcd8-15485d8c0888@gmail.com>
Date: Wed, 5 Jan 2022 01:09:45 +0300
From: Dmitry Osipenko <digetx@...il.com>
To: Hector Martin <marcan@...can.st>,
Kalle Valo <kvalo@...eaurora.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Len Brown <lenb@...nel.org>,
Arend van Spriel <aspriel@...il.com>,
Franky Lin <franky.lin@...adcom.com>,
Hante Meuleman <hante.meuleman@...adcom.com>,
Chi-hsien Lin <chi-hsien.lin@...ineon.com>,
Wright Feng <wright.feng@...ineon.com>
Cc: Sven Peter <sven@...npeter.dev>,
Alyssa Rosenzweig <alyssa@...enzweig.io>,
Mark Kettenis <kettenis@...nbsd.org>,
Rafał Miłecki <zajec5@...il.com>,
Pieter-Paul Giesberts <pieter-paul.giesberts@...adcom.com>,
Linus Walleij <linus.walleij@...aro.org>,
Hans de Goede <hdegoede@...hat.com>,
"John W. Linville" <linville@...driver.com>,
"brian m. carlson" <sandals@...stytoothpaste.net>,
Andy Shevchenko <andy.shevchenko@...il.com>,
linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-acpi@...r.kernel.org, brcm80211-dev-list.pdl@...adcom.com,
SHA-cyfmac-dev-list@...ineon.com
Subject: Re: [PATCH v2 04/35] brcmfmac: firmware: Support having multiple alt
paths
04.01.2022 11:43, Hector Martin пишет:
>>> +static int brcm_alt_fw_paths(const char *path, const char *board_type,
>>> + const char *alt_paths[BRCMF_FW_MAX_ALT_PATHS])> {
>>> char alt_path[BRCMF_FW_NAME_LEN];
>>> const char *suffix;
>>>
>>> + memset(alt_paths, 0, array_size(sizeof(*alt_paths),
>>> + BRCMF_FW_MAX_ALT_PATHS));
>> You don't need to use array_size() since size of a fixed array is
>> already known.
>>
>> memset(alt_paths, 0, sizeof(alt_paths));
> It's a function argument, so that doesn't work and actually throws a
> warning. Array function argument notation is informative only; they
> behave strictly equivalent to pointers. Try it:
>
> $ cat test.c
> #include <stdio.h>
>
> void foo(char x[42])
> {
> printf("%ld\n", sizeof(x));
> }
>
> int main() {
> char x[42];
>
> foo(x);
> }
> $ gcc test.c
> test.c: In function ‘foo’:
> test.c:5:31: warning: ‘sizeof’ on array function parameter ‘x’ will
> return size of ‘char *’ [-Wsizeof-array-argument]
> 5 | printf("%ld\n", sizeof(x));
> | ^
> test.c:3:15: note: declared here
> 3 | void foo(char x[42])
> | ~~~~~^~~~~
> $ ./a.out
> 8
Then please use "const char **alt_paths" for the function argument to
make code cleaner and add another argument to pass the number of array
elements.
static int brcm_alt_fw_paths(const char *path, const char *board_type,
const char **alt_paths, unsigned int num_paths)
{
size_t alt_paths_size = array_size(sizeof(*alt_paths), num_paths);
memset(alt_paths, 0, alt_paths_size);
}
...
Maybe even better create a dedicated struct for the alt_paths:
struct brcmf_fw_alt_paths {
const char *alt_paths[BRCMF_FW_MAX_ALT_PATHS];
unsigned int index;
};
and then use the ".index" in the brcm_free_alt_fw_paths(). I suppose
this will make code a bit nicer and easier to follow.
Powered by blists - more mailing lists