From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3B58C433FE for ; Wed, 5 Jan 2022 13:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240309AbiAENWl (ORCPT ); Wed, 5 Jan 2022 08:22:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235186AbiAENWd (ORCPT ); Wed, 5 Jan 2022 08:22:33 -0500 Received: from mail.marcansoft.com (marcansoft.com [IPv6:2a01:298:fe:f::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 139DBC061784; Wed, 5 Jan 2022 05:22:31 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id 6DA8541F4A; Wed, 5 Jan 2022 13:22:22 +0000 (UTC) To: Dmitry Osipenko , Kalle Valo , "David S. Miller" , Jakub Kicinski , Rob Herring , "Rafael J. Wysocki" , Len Brown , Arend van Spriel , Franky Lin , Hante Meuleman , Chi-hsien Lin , Wright Feng Cc: Sven Peter , Alyssa Rosenzweig , Mark Kettenis , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , Pieter-Paul Giesberts , Linus Walleij , Hans de Goede , "John W. Linville" , "brian m. carlson" , Andy Shevchenko , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com References: <20220104072658.69756-1-marcan@marcan.st> <20220104072658.69756-5-marcan@marcan.st> <5ddde705-f3fa-ff78-4d43-7a02d6efaaa6@gmail.com> <7c8d5655-a041-e291-95c1-be200233f87f@marcan.st> <8394dbcd-f500-b1ae-fcd8-15485d8c0888@gmail.com> From: Hector Martin Subject: Re: [PATCH v2 04/35] brcmfmac: firmware: Support having multiple alt paths Message-ID: <6a936aea-ada4-fe2d-7ce6-7a42788e4d63@marcan.st> Date: Wed, 5 Jan 2022 22:22:19 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <8394dbcd-f500-b1ae-fcd8-15485d8c0888@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: es-ES Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On 05/01/2022 07.09, Dmitry Osipenko wrote: > 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 >> >> 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. So you want me to do the ARRAY_SIZE at the caller side then? > > 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. > I'm confused; the array size is constant. What would index contain and why would would brcm_free_alt_fw_paths use it? Just as an iterator variable instead of using a local variable? Or do you mean count? Though, to be honest, at this point I'm considering rethinking the whole patch for this mechanism because I'm not terribly happy with the current approach and clearly you aren't either :-) Maybe it makes more sense to stop trying to compute all the alt_paths ahead of time, and just have the function compute a single one to be used just-in-time at firmware request time, and just iterate over board_types. -- Hector Martin (marcan@marcan.st) Public Key: https://mrcn.st/pub