* [PATCH] wifi: rtw89: fix clang-specific -Wvoid-pointer-to-enum-cast
@ 2023-10-19 9:38 Dmitry Antipov
2023-10-20 3:15 ` Ping-Ke Shih
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Antipov @ 2023-10-19 9:38 UTC (permalink / raw)
To: Ping-Ke Shih; +Cc: Tom Rix, Kalle Valo, linux-wireless, Dmitry Antipov
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 <dmantipov@yandex.ru>
---
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 {
+ size_t offset;
+ enum rtw89_rf_path path;
+ enum rtw89_fw_type type;
+};
+
+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 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"},
+ [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",
},
[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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH] wifi: rtw89: fix clang-specific -Wvoid-pointer-to-enum-cast
2023-10-19 9:38 [PATCH] wifi: rtw89: fix clang-specific -Wvoid-pointer-to-enum-cast Dmitry Antipov
@ 2023-10-20 3:15 ` Ping-Ke Shih
2023-10-20 4:09 ` [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing Dmitry Antipov
0 siblings, 1 reply; 5+ messages in thread
From: Ping-Ke Shih @ 2023-10-20 3:15 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Tom Rix, Kalle Valo, linux-wireless@vger.kernel.org
> -----Original Message-----
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Sent: Thursday, October 19, 2023 5:38 PM
> To: Ping-Ke Shih <pkshih@realtek.com>
> Cc: Tom Rix <trix@redhat.com>; Kalle Valo <kvalo@kernel.org>; linux-wireless@vger.kernel.org; Dmitry
> Antipov <dmantipov@yandex.ru>
> 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 <dmantipov@yandex.ru>
> ---
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing
2023-10-20 3:15 ` Ping-Ke Shih
@ 2023-10-20 4:09 ` Dmitry Antipov
2023-10-20 5:54 ` Ping-Ke Shih
2023-10-25 9:09 ` Kalle Valo
0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Antipov @ 2023-10-20 4:09 UTC (permalink / raw)
To: Ping-Ke Shih; +Cc: Tom Rix, Kalle Valo, linux-wireless, Dmitry Antipov
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_arg' to pass parameters to element handler
callbacks, and adjust all of the related bits accordingly. Compile
tested only.
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v2: prefer more subject-specific title and fix style issues (Ping-Ke Shih)
---
drivers/net/wireless/realtek/rtw89/fw.c | 71 ++++++++++++++-----------
1 file changed, 39 insertions(+), 32 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
index 7cfcf536d6fe..a732c22a2d54 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_arg {
+ size_t offset;
+ enum rtw89_rf_path rf_path;
+ enum rtw89_fw_type fw_type;
+};
+
+struct rtw89_fw_element_handler {
+ int (*fn)(struct rtw89_dev *rtwdev,
+ const struct rtw89_fw_element_hdr *elm,
+ const union rtw89_fw_element_arg arg);
+ const union rtw89_fw_element_arg arg;
+ 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_arg arg)
{
- enum rtw89_fw_type type = (enum rtw89_fw_type)data;
+ enum rtw89_fw_type type = arg.fw_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_arg arg)
{
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 = arg.rf_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)
+ const union rtw89_fw_element_arg arg)
{
const struct __rtw89_fw_txpwr_element *txpwr_elm = &elm->u.txpwr;
- const unsigned long offset = (const unsigned long)data;
+ const unsigned long offset = arg.offset;
struct rtw89_efuse *efuse = &rtwdev->efuse;
struct rtw89_txpwr_conf *conf;
@@ -644,64 +658,57 @@ 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},
+ { .fw_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},
+ { .fw_type = RTW89_FW_BBMCU1 }, NULL},
+ [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, {}, NULL},
[RTW89_FW_ELEMENT_ID_RADIO_A] = {rtw89_build_phy_tbl_from_elm,
- (const void *)RF_PATH_A, "radio A"},
+ { .rf_path = RF_PATH_A }, "radio A"},
[RTW89_FW_ELEMENT_ID_RADIO_B] = {rtw89_build_phy_tbl_from_elm,
- (const void *)RF_PATH_B, NULL},
+ { .rf_path = RF_PATH_B }, NULL},
[RTW89_FW_ELEMENT_ID_RADIO_C] = {rtw89_build_phy_tbl_from_elm,
- (const void *)RF_PATH_C, NULL},
+ { .rf_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"},
+ { .rf_path = RF_PATH_D }, NULL},
+ [RTW89_FW_ELEMENT_ID_RF_NCTL] = {rtw89_build_phy_tbl_from_elm, {}, "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",
},
[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,
},
};
@@ -742,7 +749,7 @@ int rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev)
if (!handler->fn)
goto next;
- ret = handler->fn(rtwdev, hdr, handler->data);
+ ret = handler->fn(rtwdev, hdr, handler->arg);
if (ret)
return ret;
--
2.41.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing
2023-10-20 4:09 ` [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing Dmitry Antipov
@ 2023-10-20 5:54 ` Ping-Ke Shih
2023-10-25 9:09 ` Kalle Valo
1 sibling, 0 replies; 5+ messages in thread
From: Ping-Ke Shih @ 2023-10-20 5:54 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Tom Rix, Kalle Valo, linux-wireless@vger.kernel.org
> -----Original Message-----
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Sent: Friday, October 20, 2023 12:10 PM
> To: Ping-Ke Shih <pkshih@realtek.com>
> Cc: Tom Rix <trix@redhat.com>; Kalle Valo <kvalo@kernel.org>; linux-wireless@vger.kernel.org; Dmitry
> Antipov <dmantipov@yandex.ru>
> Subject: [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing
>
> 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_arg' to pass parameters to element handler
> callbacks, and adjust all of the related bits accordingly. Compile
> tested only.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
I take this patch locally, and performance looks as regular. Thanks.
Acked-and-tested-by: Ping-Ke Shih <pkshih@realtek.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing
2023-10-20 4:09 ` [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing Dmitry Antipov
2023-10-20 5:54 ` Ping-Ke Shih
@ 2023-10-25 9:09 ` Kalle Valo
1 sibling, 0 replies; 5+ messages in thread
From: Kalle Valo @ 2023-10-25 9:09 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Ping-Ke Shih, Tom Rix, linux-wireless, Dmitry Antipov
Dmitry Antipov <dmantipov@yandex.ru> wrote:
> 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_arg' to pass parameters to element handler
> callbacks, and adjust all of the related bits accordingly. Compile
> tested only.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Patch applied to wireless-next.git, thanks.
7d7b6f2953b3 wifi: rtw89: cleanup firmware elements parsing
--
https://patchwork.kernel.org/project/linux-wireless/patch/20231020040940.33154-1-dmantipov@yandex.ru/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-25 9:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-19 9:38 [PATCH] wifi: rtw89: fix clang-specific -Wvoid-pointer-to-enum-cast Dmitry Antipov
2023-10-20 3:15 ` Ping-Ke Shih
2023-10-20 4:09 ` [PATCH] [v2] wifi: rtw89: cleanup firmware elements parsing Dmitry Antipov
2023-10-20 5:54 ` Ping-Ke Shih
2023-10-25 9:09 ` Kalle Valo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).