Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp759959rdb; Thu, 19 Oct 2023 20:15:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDu/Y0OB7pldJRx6/r4nLIH1jCv3vDjhnv8zHI4DJ0CtgFkHlMXKI21/kb+vdHO0YVo7Z8 X-Received: by 2002:a17:902:d2cf:b0:1c6:3157:29f3 with SMTP id n15-20020a170902d2cf00b001c6315729f3mr625932plc.36.1697771743640; Thu, 19 Oct 2023 20:15:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697771743; cv=none; d=google.com; s=arc-20160816; b=N9qzKdY8jg55JqqXaMfT4QSU7qxtmmHDHEB6io4ARFP+mW7bZw9P/28z2E1HsY8+7v sIHP3Y0MXvqtYc8cd3/rYdZN5u67KUzuyiFWp0pg0G8VZ3DcaJ/QPUOnsxbQZ6QAj/I2 GFdLYCOyCM9JAyRS3414vSi0y3SLomco47plB3cEganRTJYTLFINLFooWPdelV/k5oBp cPC+sWacJJe4/ciPYHPCQpXJEHhLw4Uqc+8Ecc27Am0e8PhioeL8prPiIMnXk4M6GEE8 x974hqKD+WLtkephMV6KlF7F/MbbD0o5BduHMYoGFxPaUVXo0vJvPtHYR4vAhYMPx/Ij bYTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=tj5LozyNftYIFGv5Z28TQQl0wt1Cl+n5MWLSDtba1rI=; fh=fgD1sNdZ9EUp1ak1fcfbPiHCWhG3mmwvoooQJfb0qfE=; b=hS8Bme4j+OpB9VBF+JFkz9yp2J4scuOdkkXVbxhlmh9d8RTk1PpZyNos9sTS9BBxX4 jMPm8+v1B8FlEaQDyDB5P8u8DjtRvyfncjCzAiBL8EoNiw5kjXt6EOULaK0Pwo6qto5M pSW1qw0VnmCBEb6ICkZMxBm8X0vpWMyGSwlRt0XDHbRZk2DTrfQOfAQqYpmOlFjdzSnU R9eqqcnHiXpXCRyOt3JjAOk9OlekD8lHMJgvszforMwhGA1DCoj84e/PpPB6EWb89uY/ cPSAYF/rJ/k8QgRkA6SPEQKgWp/5/pUjOnrLlZPYIs21QeqD+LXZOhb6OaB3HK0SXtNW EFXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h5-20020a170902f54500b001c3a06b4fd7si893946plf.561.2023.10.19.20.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 20:15:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6270681D0B7E; Thu, 19 Oct 2023 20:15:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233434AbjJTDPg convert rfc822-to-8bit (ORCPT + 52 others); Thu, 19 Oct 2023 23:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233405AbjJTDPe (ORCPT ); Thu, 19 Oct 2023 23:15:34 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C6851A3 for ; Thu, 19 Oct 2023 20:15:29 -0700 (PDT) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 39K3F8F003688896, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.93/5.92) with ESMTPS id 39K3F8F003688896 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 11:15:08 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Fri, 20 Oct 2023 11:15:09 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 20 Oct 2023 11:15:08 +0800 Received: from RTEXMBS04.realtek.com.tw ([fe80::40c2:6c24:2df4:e6c7]) by RTEXMBS04.realtek.com.tw ([fe80::40c2:6c24:2df4:e6c7%5]) with mapi id 15.01.2375.007; Fri, 20 Oct 2023 11:15:08 +0800 From: Ping-Ke Shih To: Dmitry Antipov CC: Tom Rix , Kalle Valo , "linux-wireless@vger.kernel.org" Subject: RE: [PATCH] wifi: rtw89: fix clang-specific -Wvoid-pointer-to-enum-cast Thread-Topic: [PATCH] wifi: rtw89: fix clang-specific -Wvoid-pointer-to-enum-cast Thread-Index: AQHaAnBCw39yzz4wEEKXQI7s1bYCxbBR/qSw Date: Fri, 20 Oct 2023 03:15:08 +0000 Message-ID: <661e7dffafdb403abc2c4cab23c7d1ed@realtek.com> References: <20231019093805.66324-1-dmantipov@yandex.ru> In-Reply-To: <20231019093805.66324-1-dmantipov@yandex.ru> Accept-Language: en-US, zh-TW Content-Language: zh-TW x-originating-ip: [172.21.71.113] x-kse-serverinfo: RTEXMBS04.realtek.com.tw, 9 x-kse-antispam-interceptor-info: fallback x-kse-antivirus-interceptor-info: fallback Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 20:15:37 -0700 (PDT) > -----Original Message----- > From: Dmitry Antipov > Sent: Thursday, October 19, 2023 5:38 PM > To: Ping-Ke Shih > Cc: Tom Rix ; Kalle Valo ; linux-wireless@vger.kernel.org; Dmitry > Antipov > Subject: [PATCH] wifi: rtw89: fix clang-specific -Wvoid-pointer-to-enum-cast Please point out "fw_element" in subject, so it would be clear to know what we are dealing with. > > When compiling with clang-18, I've noticed the following: > > drivers/net/wireless/realtek/rtw89/fw.c:389:28: warning: cast to smaller > integer type 'enum rtw89_fw_type' from 'const void *' [-Wvoid-pointer-to-enum-cast] > 389 | enum rtw89_fw_type type = (enum rtw89_fw_type)data; > | ^~~~~~~~~~~~~~~~~~~~~~~~ > drivers/net/wireless/realtek/rtw89/fw.c:569:13: warning: cast to smaller > integer type 'enum rtw89_rf_path' from 'const void *' [-Wvoid-pointer-to-enum-cast] > 569 | rf_path = (enum rtw89_rf_path)data; > | ^~~~~~~~~~~~~~~~~~~~~~~~ > > So avoid brutal everything-to-const-void-and-back casts, introduce > 'union rtw89_fw_element_data' to pass parameters to element handler > callbacks, and adjust all of the related bits accordingly. Compile > tested only. > > Signed-off-by: Dmitry Antipov > --- > drivers/net/wireless/realtek/rtw89/fw.c | 81 +++++++++++++++---------- > 1 file changed, 50 insertions(+), 31 deletions(-) > > diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c > index 7cfcf536d6fe..13a98c44d304 100644 > --- a/drivers/net/wireless/realtek/rtw89/fw.c > +++ b/drivers/net/wireless/realtek/rtw89/fw.c > @@ -13,6 +13,20 @@ > #include "reg.h" > #include "util.h" > > +union rtw89_fw_element_data { "fw_element_data" could be confusing, because it looks like data from firmware file. Prefer "fw_element_arg" or "fw_element_var", because the certain handler can handle various cases of fw_element_id. Then, third argument of handler becomes 'const union rtw89_fw_element_arg arg'. > + size_t offset; > + enum rtw89_rf_path path; > + enum rtw89_fw_type type; 'rf_path' and 'fw_type' would be clearer. > +}; > + > +struct rtw89_fw_element_handler { > + int (*fn)(struct rtw89_dev *rtwdev, > + const struct rtw89_fw_element_hdr *elm, > + const union rtw89_fw_element_data data); > + const union rtw89_fw_element_data data; > + const char *name; > +}; > + > static void rtw89_fw_c2h_cmd_handle(struct rtw89_dev *rtwdev, > struct sk_buff *skb); > static int rtw89_h2c_tx_and_wait(struct rtw89_dev *rtwdev, struct sk_buff *skb, > @@ -384,9 +398,9 @@ int __rtw89_fw_recognize(struct rtw89_dev *rtwdev, enum rtw89_fw_type type, > static > int __rtw89_fw_recognize_from_elm(struct rtw89_dev *rtwdev, > const struct rtw89_fw_element_hdr *elm, > - const void *data) > + const union rtw89_fw_element_data data) > { > - enum rtw89_fw_type type = (enum rtw89_fw_type)data; > + enum rtw89_fw_type type = data.type; > struct rtw89_fw_suit *fw_suit; > > fw_suit = rtw89_fw_suit_get(rtwdev, type); > @@ -542,7 +556,7 @@ int rtw89_fw_recognize(struct rtw89_dev *rtwdev) > static > int rtw89_build_phy_tbl_from_elm(struct rtw89_dev *rtwdev, > const struct rtw89_fw_element_hdr *elm, > - const void *data) > + const union rtw89_fw_element_data data) > { > struct rtw89_fw_elm_info *elm_info = &rtwdev->fw.elm_info; > struct rtw89_phy_table *tbl; > @@ -566,7 +580,7 @@ int rtw89_build_phy_tbl_from_elm(struct rtw89_dev *rtwdev, > case RTW89_FW_ELEMENT_ID_RADIO_B: > case RTW89_FW_ELEMENT_ID_RADIO_C: > case RTW89_FW_ELEMENT_ID_RADIO_D: > - rf_path = (enum rtw89_rf_path)data; > + rf_path = data.path; > idx = elm->u.reg2.idx; > > elm_info->rf_radio[idx] = tbl; > @@ -604,10 +618,10 @@ int rtw89_build_phy_tbl_from_elm(struct rtw89_dev *rtwdev, > static > int rtw89_fw_recognize_txpwr_from_elm(struct rtw89_dev *rtwdev, > const struct rtw89_fw_element_hdr *elm, > - const void *data) > + union rtw89_fw_element_data data) const union rtw89_fw_element_data data miss 'const' here. > { > const struct __rtw89_fw_txpwr_element *txpwr_elm = &elm->u.txpwr; > - const unsigned long offset = (const unsigned long)data; > + const unsigned long offset = data.offset; > struct rtw89_efuse *efuse = &rtwdev->efuse; > struct rtw89_txpwr_conf *conf; > > @@ -644,64 +658,69 @@ int rtw89_fw_recognize_txpwr_from_elm(struct rtw89_dev *rtwdev, > return 0; > } > > -struct rtw89_fw_element_handler { > - int (*fn)(struct rtw89_dev *rtwdev, > - const struct rtw89_fw_element_hdr *elm, const void *data); > - const void *data; > - const char *name; > -}; > - > static const struct rtw89_fw_element_handler __fw_element_handlers[] = { > [RTW89_FW_ELEMENT_ID_BBMCU0] = {__rtw89_fw_recognize_from_elm, > - (const void *)RTW89_FW_BBMCU0, NULL}, > + { .type = RTW89_FW_BBMCU0 }, NULL}, > [RTW89_FW_ELEMENT_ID_BBMCU1] = {__rtw89_fw_recognize_from_elm, > - (const void *)RTW89_FW_BBMCU1, NULL}, > - [RTW89_FW_ELEMENT_ID_BB_REG] = {rtw89_build_phy_tbl_from_elm, NULL, "BB"}, > - [RTW89_FW_ELEMENT_ID_BB_GAIN] = {rtw89_build_phy_tbl_from_elm, NULL, NULL}, > + { .type = RTW89_FW_BBMCU1 }, NULL}, > + [RTW89_FW_ELEMENT_ID_BB_REG] = {rtw89_build_phy_tbl_from_elm, > + { 0 }, "BB"}, Can we just '{}' instead? And, straighten it to single one line as before, like [RTW89_FW_ELEMENT_ID_BB_REG] = {rtw89_build_phy_tbl_from_elm, {], "BB"}, > + [RTW89_FW_ELEMENT_ID_BB_GAIN] = {rtw89_build_phy_tbl_from_elm, > + { 0 }, NULL}, > [RTW89_FW_ELEMENT_ID_RADIO_A] = {rtw89_build_phy_tbl_from_elm, > - (const void *)RF_PATH_A, "radio A"}, > + { .path = RF_PATH_A }, "radio A"}, > [RTW89_FW_ELEMENT_ID_RADIO_B] = {rtw89_build_phy_tbl_from_elm, > - (const void *)RF_PATH_B, NULL}, > + { .path = RF_PATH_B }, NULL}, > [RTW89_FW_ELEMENT_ID_RADIO_C] = {rtw89_build_phy_tbl_from_elm, > - (const void *)RF_PATH_C, NULL}, > + { .path = RF_PATH_C }, NULL}, > [RTW89_FW_ELEMENT_ID_RADIO_D] = {rtw89_build_phy_tbl_from_elm, > - (const void *)RF_PATH_D, NULL}, > - [RTW89_FW_ELEMENT_ID_RF_NCTL] = {rtw89_build_phy_tbl_from_elm, NULL, "NCTL"}, > + { .path = RF_PATH_D }, NULL}, > + [RTW89_FW_ELEMENT_ID_RF_NCTL] = {rtw89_build_phy_tbl_from_elm, > + { 0 }, "NCTL"}, > [RTW89_FW_ELEMENT_ID_TXPWR_BYRATE] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, byrate.conf), "TXPWR", > + { .offset = offsetof(struct rtw89_rfe_data, byrate.conf) }, > + "TXPWR", Prefer keeping original single-one-line style. > }, > [RTW89_FW_ELEMENT_ID_TXPWR_LMT_2GHZ] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, lmt_2ghz.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, lmt_2ghz.conf) }, > + NULL, > }, > [RTW89_FW_ELEMENT_ID_TXPWR_LMT_5GHZ] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, lmt_5ghz.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, lmt_5ghz.conf) }, > + NULL, > }, > [RTW89_FW_ELEMENT_ID_TXPWR_LMT_6GHZ] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, lmt_6ghz.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, lmt_6ghz.conf) }, > + NULL, > }, > [RTW89_FW_ELEMENT_ID_TXPWR_LMT_RU_2GHZ] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, lmt_ru_2ghz.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, lmt_ru_2ghz.conf) }, > + NULL, > }, > [RTW89_FW_ELEMENT_ID_TXPWR_LMT_RU_5GHZ] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, lmt_ru_5ghz.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, lmt_ru_5ghz.conf) }, > + NULL, > }, > [RTW89_FW_ELEMENT_ID_TXPWR_LMT_RU_6GHZ] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, lmt_ru_6ghz.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, lmt_ru_6ghz.conf) }, > + NULL, > }, > [RTW89_FW_ELEMENT_ID_TX_SHAPE_LMT] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, tx_shape_lmt.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, tx_shape_lmt.conf) }, > + NULL, > }, > [RTW89_FW_ELEMENT_ID_TX_SHAPE_LMT_RU] = { > rtw89_fw_recognize_txpwr_from_elm, > - (const void *)offsetof(struct rtw89_rfe_data, tx_shape_lmt_ru.conf), NULL, > + { .offset = offsetof(struct rtw89_rfe_data, tx_shape_lmt_ru.conf) }, > + NULL, > }, > }; > > -- > 2.41.0