From patchwork Sun Aug 23 19:40:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 262037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06CBDC433DF for ; Sun, 23 Aug 2020 19:40:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE5FD20774 for ; Sun, 23 Aug 2020 19:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726600AbgHWTkV (ORCPT ); Sun, 23 Aug 2020 15:40:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:50592 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725996AbgHWTkU (ORCPT ); Sun, 23 Aug 2020 15:40:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BC73FAEB1; Sun, 23 Aug 2020 19:40:47 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 1CEA66030D; Sun, 23 Aug 2020 21:40:18 +0200 (CEST) Message-Id: <06083ab4701848eeb56afec9a5d8b757dd6cb399.1598210544.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool v2 1/9] netlink: get rid of signed/unsigned comparison warnings To: netdev@vger.kernel.org Cc: Andrew Lunn Date: Sun, 23 Aug 2020 21:40:18 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use unsigned types where appropriate to get rid of compiler warnings about comparison between signed and unsigned integer values in netlink code. v2: avoid casts in dump_features() Signed-off-by: Michal Kubecek --- netlink/features.c | 6 +++--- netlink/netlink.c | 4 ++-- netlink/netlink.h | 2 +- netlink/nlsock.c | 2 +- netlink/parser.c | 2 +- netlink/settings.c | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/netlink/features.c b/netlink/features.c index 133529da2b9f..c4105435f39d 100644 --- a/netlink/features.c +++ b/netlink/features.c @@ -109,9 +109,9 @@ static bool flag_pattern_match(const char *name, const char *pattern) int dump_features(const struct nlattr *const *tb, const struct stringset *feature_names) { + unsigned int *feature_flags = NULL; struct feature_results results; unsigned int i, j; - int *feature_flags = NULL; int ret; ret = prepare_feature_results(tb, &results); @@ -126,7 +126,7 @@ int dump_features(const struct nlattr *const *tb, /* map netdev features to legacy flags */ for (i = 0; i < results.count; i++) { const char *name = get_string(feature_names, i); - feature_flags[i] = -1; + feature_flags[i] = UINT_MAX; if (!name || !*name) continue; @@ -177,7 +177,7 @@ int dump_features(const struct nlattr *const *tb, for (i = 0; i < results.count; i++) { const char *name = get_string(feature_names, i); - if (!name || !*name || feature_flags[i] >= 0) + if (!name || !*name || feature_flags[i] != UINT_MAX) continue; dump_feature(&results, NULL, NULL, i, name, ""); } diff --git a/netlink/netlink.c b/netlink/netlink.c index 76b6e825b1d0..e42d57076a4b 100644 --- a/netlink/netlink.c +++ b/netlink/netlink.c @@ -33,9 +33,9 @@ int nomsg_reply_cb(const struct nlmsghdr *nlhdr, void *data __maybe_unused) int attr_cb(const struct nlattr *attr, void *data) { const struct attr_tb_info *tb_info = data; - int type = mnl_attr_get_type(attr); + uint16_t type = mnl_attr_get_type(attr); - if (type >= 0 && type <= tb_info->max_type) + if (type <= tb_info->max_type) tb_info->tb[type] = attr; return MNL_CB_OK; diff --git a/netlink/netlink.h b/netlink/netlink.h index a4984c82ae76..dd4a02bcc916 100644 --- a/netlink/netlink.h +++ b/netlink/netlink.h @@ -45,7 +45,7 @@ struct nl_context { const char *cmd; const char *param; char **argp; - int argc; + unsigned int argc; bool ioctl_fallback; bool wildcard_unsupported; }; diff --git a/netlink/nlsock.c b/netlink/nlsock.c index c3f09b6ee9ab..ef31d8c33b29 100644 --- a/netlink/nlsock.c +++ b/netlink/nlsock.c @@ -168,7 +168,7 @@ static void debug_msg(struct nl_socket *nlsk, const void *msg, unsigned int len, * * Return: error code extracted from the message */ -static int nlsock_process_ack(struct nlmsghdr *nlhdr, ssize_t len, +static int nlsock_process_ack(struct nlmsghdr *nlhdr, unsigned long len, unsigned int suppress_nlerr, bool pretty) { const struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {}; diff --git a/netlink/parser.c b/netlink/parser.c index 395bd5743af9..c5a368a65a7a 100644 --- a/netlink/parser.c +++ b/netlink/parser.c @@ -604,7 +604,7 @@ static int parse_numeric_bitset(struct nl_context *nlctx, uint16_t type, parser_err_invalid_value(nlctx, arg); return -EINVAL; } - len1 = maskptr ? (maskptr - arg) : strlen(arg); + len1 = maskptr ? (unsigned int)(maskptr - arg) : strlen(arg); nwords = DIV_ROUND_UP(len1, 8); nbits = 0; diff --git a/netlink/settings.c b/netlink/settings.c index de35ad173627..99d047a3e497 100644 --- a/netlink/settings.c +++ b/netlink/settings.c @@ -276,10 +276,10 @@ int dump_link_modes(struct nl_context *nlctx, const struct nlattr *bitset, const struct nlattr *bitset_tb[ETHTOOL_A_BITSET_MAX + 1] = {}; DECLARE_ATTR_TB_INFO(bitset_tb); const unsigned int before_len = strlen(before); + unsigned int prev = UINT_MAX - 1; const struct nlattr *bits; const struct nlattr *bit; bool first = true; - int prev = -2; bool nomask; int ret; @@ -333,7 +333,7 @@ int dump_link_modes(struct nl_context *nlctx, const struct nlattr *bitset, if (first) first = false; /* ugly hack to preserve old output format */ - if (class == LM_CLASS_REAL && (prev == idx - 1) && + if (class == LM_CLASS_REAL && (idx == prev + 1) && prev < link_modes_count && link_modes[prev].class == LM_CLASS_REAL && link_modes[prev].duplex == DUPLEX_HALF) @@ -375,7 +375,7 @@ int dump_link_modes(struct nl_context *nlctx, const struct nlattr *bitset, first = false; } else { /* ugly hack to preserve old output format */ - if ((class == LM_CLASS_REAL) && (prev == idx - 1) && + if ((class == LM_CLASS_REAL) && (idx == prev + 1) && (prev < link_modes_count) && (link_modes[prev].class == LM_CLASS_REAL) && (link_modes[prev].duplex == DUPLEX_HALF)) From patchwork Sun Aug 23 19:40:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 262036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1C19C433E1 for ; Sun, 23 Aug 2020 19:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D31C220720 for ; Sun, 23 Aug 2020 19:40:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726753AbgHWTk0 (ORCPT ); Sun, 23 Aug 2020 15:40:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:50652 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725996AbgHWTkX (ORCPT ); Sun, 23 Aug 2020 15:40:23 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B7F07AEC4; Sun, 23 Aug 2020 19:40:50 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 224F06030D; Sun, 23 Aug 2020 21:40:21 +0200 (CEST) Message-Id: <2a1370f2ffe49011dbfe8c32ef455d3514a6cdd0.1598210544.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool v2 2/9] ioctl: check presence of eeprom length argument properly To: netdev@vger.kernel.org Cc: Andrew Lunn Date: Sun, 23 Aug 2020 21:40:21 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In do_geeprom(), do_seprom() and do_getmodule(), check if user used "length" command line argument is done by setting the value to -1 before parsing and checking if it changed. This is quite ugly and also causes compiler warnings as the variable is u32. Use proper "seen" flag to let parser tell us if the argument was used. Signed-off-by: Michal Kubecek Reviewed-by: Andrew Lunn --- ethtool.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ethtool.c b/ethtool.c index c4ad186cd390..4fa7a2c1716f 100644 --- a/ethtool.c +++ b/ethtool.c @@ -3184,10 +3184,12 @@ static int do_geeprom(struct cmd_context *ctx) int geeprom_changed = 0; int geeprom_dump_raw = 0; u32 geeprom_offset = 0; - u32 geeprom_length = -1; + u32 geeprom_length = 0; + int geeprom_length_seen = 0; struct cmdline_info cmdline_geeprom[] = { { "offset", CMDL_U32, &geeprom_offset, NULL }, - { "length", CMDL_U32, &geeprom_length, NULL }, + { "length", CMDL_U32, &geeprom_length, NULL, + 0, &geeprom_length_seen }, { "raw", CMDL_BOOL, &geeprom_dump_raw, NULL }, }; int err; @@ -3204,7 +3206,7 @@ static int do_geeprom(struct cmd_context *ctx) return 74; } - if (geeprom_length == -1) + if (!geeprom_length_seen) geeprom_length = drvinfo.eedump_len; if (drvinfo.eedump_len < geeprom_offset + geeprom_length) @@ -3234,14 +3236,16 @@ static int do_seeprom(struct cmd_context *ctx) { int seeprom_changed = 0; u32 seeprom_magic = 0; - u32 seeprom_length = -1; + u32 seeprom_length = 0; u32 seeprom_offset = 0; u8 seeprom_value = 0; + int seeprom_length_seen = 0; int seeprom_value_seen = 0; struct cmdline_info cmdline_seeprom[] = { { "magic", CMDL_U32, &seeprom_magic, NULL }, { "offset", CMDL_U32, &seeprom_offset, NULL }, - { "length", CMDL_U32, &seeprom_length, NULL }, + { "length", CMDL_U32, &seeprom_length, NULL, + 0, &seeprom_length_seen }, { "value", CMDL_U8, &seeprom_value, NULL, 0, &seeprom_value_seen }, }; @@ -3262,7 +3266,7 @@ static int do_seeprom(struct cmd_context *ctx) if (seeprom_value_seen) seeprom_length = 1; - if (seeprom_length == -1) + if (!seeprom_length_seen) seeprom_length = drvinfo.eedump_len; if (drvinfo.eedump_len < seeprom_offset + seeprom_length) { @@ -4538,15 +4542,17 @@ static int do_getmodule(struct cmd_context *ctx) struct ethtool_modinfo modinfo; struct ethtool_eeprom *eeprom; u32 geeprom_offset = 0; - u32 geeprom_length = -1; + u32 geeprom_length = 0; int geeprom_changed = 0; int geeprom_dump_raw = 0; int geeprom_dump_hex = 0; + int geeprom_length_seen = 0; int err; struct cmdline_info cmdline_geeprom[] = { { "offset", CMDL_U32, &geeprom_offset, NULL }, - { "length", CMDL_U32, &geeprom_length, NULL }, + { "length", CMDL_U32, &geeprom_length, NULL, + 0, &geeprom_length_seen }, { "raw", CMDL_BOOL, &geeprom_dump_raw, NULL }, { "hex", CMDL_BOOL, &geeprom_dump_hex, NULL }, }; @@ -4566,7 +4572,7 @@ static int do_getmodule(struct cmd_context *ctx) return 1; } - if (geeprom_length == -1) + if (!geeprom_length_seen) geeprom_length = modinfo.eeprom_len; if (modinfo.eeprom_len < geeprom_offset + geeprom_length) From patchwork Sun Aug 23 19:40:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 262035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBDFEC433DF for ; Sun, 23 Aug 2020 19:40:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DDCD20720 for ; Sun, 23 Aug 2020 19:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726852AbgHWTke (ORCPT ); Sun, 23 Aug 2020 15:40:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:50778 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbgHWTkc (ORCPT ); Sun, 23 Aug 2020 15:40:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C73CCAEB1; Sun, 23 Aug 2020 19:40:59 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 332606030D; Sun, 23 Aug 2020 21:40:30 +0200 (CEST) Message-Id: <92e8bbdd5149635334f7fb0f716a29cbadeb917f.1598210544.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool v2 5/9] ioctl: get rid of signed/unsigned comparison warnings To: netdev@vger.kernel.org Cc: Andrew Lunn Date: Sun, 23 Aug 2020 21:40:30 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Comparison between signed and unsigned values is fragile and causes compiler warnings with recent compilers and stricter CFLAGS. Prevent such comparisons either by properly declaring variables (mostly loop iterators) as unsigned or by explicitly casting one side of the comparison. v2: rework argc related changes and split them into a separate patch Signed-off-by: Michal Kubecek --- ethtool.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/ethtool.c b/ethtool.c index 7c7e98957c80..3c30824016d5 100644 --- a/ethtool.c +++ b/ethtool.c @@ -641,8 +641,9 @@ static void dump_link_caps(const char *prefix, const char *an_prefix, "200000baseCR4/Full" }, }; int indent; - int did1, new_line_pend, i; + int did1, new_line_pend; int fecreported = 0; + unsigned int i; /* Indent just like the separate functions used to */ indent = strlen(prefix) + 14; @@ -1071,7 +1072,7 @@ void dump_hex(FILE *file, const u8 *data, int len, int offset) static int dump_regs(int gregs_dump_raw, int gregs_dump_hex, struct ethtool_drvinfo *info, struct ethtool_regs *regs) { - int i; + unsigned int i; if (gregs_dump_raw) { fwrite(regs->data, regs->len, 1, stdout); @@ -1128,7 +1129,8 @@ static int dump_eeprom(int geeprom_dump_raw, static int dump_test(struct ethtool_test *test, struct ethtool_gstrings *strings) { - int i, rc; + unsigned int i; + int rc; rc = test->flags & ETH_TEST_FL_FAILED; fprintf(stdout, "The test result is %s\n", rc ? "FAIL" : "PASS"); @@ -1359,7 +1361,7 @@ static void dump_one_feature(const char *indent, const char *name, : ""); } -static int linux_version_code(void) +static unsigned int linux_version_code(void) { struct utsname utsname; unsigned version, patchlevel, sublevel = 0; @@ -1375,10 +1377,10 @@ static void dump_features(const struct feature_defs *defs, const struct feature_state *state, const struct feature_state *ref_state) { - int kernel_ver = linux_version_code(); - u32 value; + unsigned int kernel_ver = linux_version_code(); + unsigned int i, j; int indent; - int i, j; + u32 value; for (i = 0; i < OFF_FLAG_DEF_SIZE; i++) { /* Don't show features whose state is unknown on this @@ -1411,7 +1413,7 @@ static void dump_features(const struct feature_defs *defs, /* Show matching features */ for (j = 0; j < defs->n_features; j++) { - if (defs->def[j].off_flag_index != i) + if (defs->def[j].off_flag_index != (int)i) continue; if (defs->off_flag_matched[i] != 1) /* Show all matching feature states */ @@ -1668,8 +1670,8 @@ static struct feature_defs *get_feature_defs(struct cmd_context *ctx) { struct ethtool_gstrings *names; struct feature_defs *defs; + unsigned int i, j; u32 n_features; - int i, j; names = get_stringset(ctx, ETH_SS_FEATURES, 0, 1); if (names) { @@ -2236,8 +2238,8 @@ static int do_sfeatures(struct cmd_context *ctx) struct cmdline_info *cmdline_features; struct feature_state *old_state, *new_state; struct ethtool_value eval; + unsigned int i, j; int err, rc; - int i, j; defs = get_feature_defs(ctx); if (!defs) { @@ -2317,7 +2319,7 @@ static int do_sfeatures(struct cmd_context *ctx) continue; for (j = 0; j < defs->n_features; j++) { - if (defs->def[j].off_flag_index != i || + if (defs->def[j].off_flag_index != (int)i || !FEATURE_BIT_IS_SET( old_state->features.features, j, available) || @@ -3869,7 +3871,7 @@ static int do_srxfh(struct cmd_context *ctx) char *hfunc_name = NULL; char *hkey = NULL; int err = 0; - int i; + unsigned int i; u32 arg_num = 0, indir_bytes = 0; u32 req_hfunc = 0; u32 entry_size = sizeof(rss_head.rss_config[0]); @@ -4135,7 +4137,8 @@ static int do_flash(struct cmd_context *ctx) static int do_permaddr(struct cmd_context *ctx) { - int i, err; + unsigned int i; + int err; struct ethtool_perm_addr *epaddr; epaddr = malloc(sizeof(struct ethtool_perm_addr) + MAX_ADDR_LEN); @@ -4750,7 +4753,7 @@ static int do_stunable(struct cmd_context *ctx) struct cmdline_info cmdline_tunable[TUNABLES_INFO_SIZE]; struct ethtool_tunable_info *tinfo = tunables_info; int changed = 0; - int i; + unsigned int i; for (i = 0; i < TUNABLES_INFO_SIZE; i++) { cmdline_tunable[i].name = tunable_strings[tinfo[i].t_id]; From patchwork Sun Aug 23 19:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 262034 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UPPERCASE_50_75 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B50AC433E1 for ; Sun, 23 Aug 2020 19:40:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6440E20720 for ; Sun, 23 Aug 2020 19:40:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbgHWTkn (ORCPT ); Sun, 23 Aug 2020 15:40:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:50814 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbgHWTkj (ORCPT ); Sun, 23 Aug 2020 15:40:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D36EFAEC4; Sun, 23 Aug 2020 19:41:05 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 3E43E6030D; Sun, 23 Aug 2020 21:40:36 +0200 (CEST) Message-Id: <562b9a44ae5c6af4c801d8abf3a7cf318d2bfd32.1598210544.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool v2 7/9] settings: simplify link_mode_info[] initializers To: netdev@vger.kernel.org Cc: Andrew Lunn Date: Sun, 23 Aug 2020 21:40:36 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use macro helpers to make link_mode_info[] initializers easier to read and less prone to mistakes. As a bonus, this gets rid of "missing field initializer" warnings in netlink/settings.c This commit should have no effect on resulting code (checked with gcc-11 and -O2). Signed-off-by: Michal Kubecek Reviewed-by: Andrew Lunn --- netlink/settings.c | 236 +++++++++++++++++---------------------------- 1 file changed, 86 insertions(+), 150 deletions(-) diff --git a/netlink/settings.c b/netlink/settings.c index 99d047a3e497..935724e799da 100644 --- a/netlink/settings.c +++ b/netlink/settings.c @@ -64,160 +64,96 @@ static const char *const names_transceiver[] = { * there is little chance of getting them separated any time soon so let's * sort them out ourselves */ +#define __REAL(_speed) \ + { .class = LM_CLASS_REAL, .speed = _speed, .duplex = DUPLEX_FULL } +#define __HALF_DUPLEX(_speed) \ + { .class = LM_CLASS_REAL, .speed = _speed, .duplex = DUPLEX_HALF } +#define __SPECIAL(_class) \ + { .class = LM_CLASS_ ## _class } + static const struct link_mode_info link_modes[] = { - [ETHTOOL_LINK_MODE_10baseT_Half_BIT] = - { LM_CLASS_REAL, 10, DUPLEX_HALF }, - [ETHTOOL_LINK_MODE_10baseT_Full_BIT] = - { LM_CLASS_REAL, 10, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100baseT_Half_BIT] = - { LM_CLASS_REAL, 100, DUPLEX_HALF }, - [ETHTOOL_LINK_MODE_100baseT_Full_BIT] = - { LM_CLASS_REAL, 100, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_1000baseT_Half_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_HALF }, - [ETHTOOL_LINK_MODE_1000baseT_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_Autoneg_BIT] = - { LM_CLASS_AUTONEG }, - [ETHTOOL_LINK_MODE_TP_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_AUI_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_MII_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_FIBRE_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_BNC_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_10000baseT_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_Pause_BIT] = - { LM_CLASS_PAUSE }, - [ETHTOOL_LINK_MODE_Asym_Pause_BIT] = - { LM_CLASS_PAUSE }, - [ETHTOOL_LINK_MODE_2500baseX_Full_BIT] = - { LM_CLASS_REAL, 2500, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_Backplane_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_1000baseKX_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseKR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT] = - { LM_CLASS_REAL, 20000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT] = - { LM_CLASS_REAL, 20000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_25000baseCR_Full_BIT] = - { LM_CLASS_REAL, 25000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_25000baseKR_Full_BIT] = - { LM_CLASS_REAL, 25000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_25000baseSR_Full_BIT] = - { LM_CLASS_REAL, 25000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_1000baseX_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseCR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseSR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseLR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseER_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_2500baseT_Full_BIT] = - { LM_CLASS_REAL, 2500, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_5000baseT_Full_BIT] = - { LM_CLASS_REAL, 5000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_FEC_NONE_BIT] = - { LM_CLASS_FEC }, - [ETHTOOL_LINK_MODE_FEC_RS_BIT] = - { LM_CLASS_FEC }, - [ETHTOOL_LINK_MODE_FEC_BASER_BIT] = - { LM_CLASS_FEC }, - [ETHTOOL_LINK_MODE_50000baseKR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseSR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseCR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseDR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100baseT1_Full_BIT] = - { LM_CLASS_REAL, 100, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_1000baseT1_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_FEC_LLRS_BIT] = - { LM_CLASS_FEC }, + [ETHTOOL_LINK_MODE_10baseT_Half_BIT] = __HALF_DUPLEX(10), + [ETHTOOL_LINK_MODE_10baseT_Full_BIT] = __REAL(10), + [ETHTOOL_LINK_MODE_100baseT_Half_BIT] = __HALF_DUPLEX(100), + [ETHTOOL_LINK_MODE_100baseT_Full_BIT] = __REAL(100), + [ETHTOOL_LINK_MODE_1000baseT_Half_BIT] = __HALF_DUPLEX(1000), + [ETHTOOL_LINK_MODE_1000baseT_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_Autoneg_BIT] = __SPECIAL(AUTONEG), + [ETHTOOL_LINK_MODE_TP_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_AUI_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_MII_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_FIBRE_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_BNC_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_10000baseT_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_Pause_BIT] = __SPECIAL(PAUSE), + [ETHTOOL_LINK_MODE_Asym_Pause_BIT] = __SPECIAL(PAUSE), + [ETHTOOL_LINK_MODE_2500baseX_Full_BIT] = __REAL(2500), + [ETHTOOL_LINK_MODE_Backplane_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_1000baseKX_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseKR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT] = __REAL(20000), + [ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT] = __REAL(20000), + [ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_25000baseCR_Full_BIT] = __REAL(25000), + [ETHTOOL_LINK_MODE_25000baseKR_Full_BIT] = __REAL(25000), + [ETHTOOL_LINK_MODE_25000baseSR_Full_BIT] = __REAL(25000), + [ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_1000baseX_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_10000baseCR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseSR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseLR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseER_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_2500baseT_Full_BIT] = __REAL(2500), + [ETHTOOL_LINK_MODE_5000baseT_Full_BIT] = __REAL(5000), + [ETHTOOL_LINK_MODE_FEC_NONE_BIT] = __SPECIAL(FEC), + [ETHTOOL_LINK_MODE_FEC_RS_BIT] = __SPECIAL(FEC), + [ETHTOOL_LINK_MODE_FEC_BASER_BIT] = __SPECIAL(FEC), + [ETHTOOL_LINK_MODE_50000baseKR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseSR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseCR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseDR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_100baseT1_Full_BIT] = __REAL(100), + [ETHTOOL_LINK_MODE_1000baseT1_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_FEC_LLRS_BIT] = __SPECIAL(FEC), }; const unsigned int link_modes_count = ARRAY_SIZE(link_modes); +#undef __REAL +#undef __HALF_DUPLEX +#undef __SPECIAL + static bool lm_class_match(unsigned int mode, enum link_mode_class class) { unsigned int mode_class = (mode < link_modes_count) ? From patchwork Sun Aug 23 19:40:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 262033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57989C433DF for ; Sun, 23 Aug 2020 19:40:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2824720720 for ; Sun, 23 Aug 2020 19:40:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbgHWTkr (ORCPT ); Sun, 23 Aug 2020 15:40:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:50830 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbgHWTkm (ORCPT ); Sun, 23 Aug 2020 15:40:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D9AB8AEB1; Sun, 23 Aug 2020 19:41:08 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 43F566030D; Sun, 23 Aug 2020 21:40:39 +0200 (CEST) Message-Id: <0457d46f26350a7ba65c596898069d585c7cd90d.1598210544.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool v2 8/9] ioctl: convert cmdline_info arrays to named initializers To: netdev@vger.kernel.org Cc: Andrew Lunn Date: Sun, 23 Aug 2020 21:40:39 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To get rid of remaining "missing field initializer" compiler warnings, convert arrays of struct cmdline_info used for command line parser to named initializers. This also makes the initializers easier to read. This commit should have no effect on resulting code (checked with gcc-11 and -O2). Signed-off-by: Michal Kubecek Reviewed-by: Andrew Lunn --- ethtool.c | 378 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 296 insertions(+), 82 deletions(-) diff --git a/ethtool.c b/ethtool.c index 3c30824016d5..e32a93b41088 100644 --- a/ethtool.c +++ b/ethtool.c @@ -1825,10 +1825,24 @@ static int do_spause(struct cmd_context *ctx) int pause_rx_wanted = -1; int pause_tx_wanted = -1; struct cmdline_info cmdline_pause[] = { - { "autoneg", CMDL_BOOL, &pause_autoneg_wanted, - &epause.autoneg }, - { "rx", CMDL_BOOL, &pause_rx_wanted, &epause.rx_pause }, - { "tx", CMDL_BOOL, &pause_tx_wanted, &epause.tx_pause }, + { + .name = "autoneg", + .type = CMDL_BOOL, + .wanted_val = &pause_autoneg_wanted, + .ioctl_val = &epause.autoneg, + }, + { + .name = "rx", + .type = CMDL_BOOL, + .wanted_val = &pause_rx_wanted, + .ioctl_val = &epause.rx_pause, + }, + { + .name = "tx", + .type = CMDL_BOOL, + .wanted_val = &pause_tx_wanted, + .ioctl_val = &epause.tx_pause, + }, }; int err, changed = 0; @@ -1868,12 +1882,30 @@ static int do_sring(struct cmd_context *ctx) s32 ring_rx_jumbo_wanted = -1; s32 ring_tx_wanted = -1; struct cmdline_info cmdline_ring[] = { - { "rx", CMDL_S32, &ring_rx_wanted, &ering.rx_pending }, - { "rx-mini", CMDL_S32, &ring_rx_mini_wanted, - &ering.rx_mini_pending }, - { "rx-jumbo", CMDL_S32, &ring_rx_jumbo_wanted, - &ering.rx_jumbo_pending }, - { "tx", CMDL_S32, &ring_tx_wanted, &ering.tx_pending }, + { + .name = "rx", + .type = CMDL_S32, + .wanted_val = &ring_rx_wanted, + .ioctl_val = &ering.rx_pending, + }, + { + .name = "rx-mini", + .type = CMDL_S32, + .wanted_val = &ring_rx_mini_wanted, + .ioctl_val = &ering.rx_mini_pending, + }, + { + .name = "rx-jumbo", + .type = CMDL_S32, + .wanted_val = &ring_rx_jumbo_wanted, + .ioctl_val = &ering.rx_jumbo_pending, + }, + { + .name = "tx", + .type = CMDL_S32, + .wanted_val = &ring_tx_wanted, + .ioctl_val = &ering.tx_pending, + }, }; int err, changed = 0; @@ -1937,12 +1969,30 @@ static int do_schannels(struct cmd_context *ctx) s32 channels_other_wanted = -1; s32 channels_combined_wanted = -1; struct cmdline_info cmdline_channels[] = { - { "rx", CMDL_S32, &channels_rx_wanted, &echannels.rx_count }, - { "tx", CMDL_S32, &channels_tx_wanted, &echannels.tx_count }, - { "other", CMDL_S32, &channels_other_wanted, - &echannels.other_count }, - { "combined", CMDL_S32, &channels_combined_wanted, - &echannels.combined_count }, + { + .name = "rx", + .type = CMDL_S32, + .wanted_val = &channels_rx_wanted, + .ioctl_val = &echannels.rx_count, + }, + { + .name = "tx", + .type = CMDL_S32, + .wanted_val = &channels_tx_wanted, + .ioctl_val = &echannels.tx_count, + }, + { + .name = "other", + .type = CMDL_S32, + .wanted_val = &channels_other_wanted, + .ioctl_val = &echannels.other_count, + }, + { + .name = "combined", + .type = CMDL_S32, + .wanted_val = &channels_combined_wanted, + .ioctl_val = &echannels.combined_count, + }, }; int err, changed = 0; @@ -2052,50 +2102,138 @@ static int do_gcoalesce(struct cmd_context *ctx) #define COALESCE_CMDLINE_INFO(__ecoal) \ { \ - { "adaptive-rx", CMDL_BOOL, &coal_adaptive_rx_wanted, \ - &__ecoal.use_adaptive_rx_coalesce }, \ - { "adaptive-tx", CMDL_BOOL, &coal_adaptive_tx_wanted, \ - &__ecoal.use_adaptive_tx_coalesce }, \ - { "sample-interval", CMDL_S32, &coal_sample_rate_wanted, \ - &__ecoal.rate_sample_interval }, \ - { "stats-block-usecs", CMDL_S32, &coal_stats_wanted, \ - &__ecoal.stats_block_coalesce_usecs }, \ - { "pkt-rate-low", CMDL_S32, &coal_pkt_rate_low_wanted, \ - &__ecoal.pkt_rate_low }, \ - { "pkt-rate-high", CMDL_S32, &coal_pkt_rate_high_wanted, \ - &__ecoal.pkt_rate_high }, \ - { "rx-usecs", CMDL_S32, &coal_rx_usec_wanted, \ - &__ecoal.rx_coalesce_usecs }, \ - { "rx-frames", CMDL_S32, &coal_rx_frames_wanted, \ - &__ecoal.rx_max_coalesced_frames }, \ - { "rx-usecs-irq", CMDL_S32, &coal_rx_usec_irq_wanted, \ - &__ecoal.rx_coalesce_usecs_irq }, \ - { "rx-frames-irq", CMDL_S32, &coal_rx_frames_irq_wanted, \ - &__ecoal.rx_max_coalesced_frames_irq }, \ - { "tx-usecs", CMDL_S32, &coal_tx_usec_wanted, \ - &__ecoal.tx_coalesce_usecs }, \ - { "tx-frames", CMDL_S32, &coal_tx_frames_wanted, \ - &__ecoal.tx_max_coalesced_frames }, \ - { "tx-usecs-irq", CMDL_S32, &coal_tx_usec_irq_wanted, \ - &__ecoal.tx_coalesce_usecs_irq }, \ - { "tx-frames-irq", CMDL_S32, &coal_tx_frames_irq_wanted, \ - &__ecoal.tx_max_coalesced_frames_irq }, \ - { "rx-usecs-low", CMDL_S32, &coal_rx_usec_low_wanted, \ - &__ecoal.rx_coalesce_usecs_low }, \ - { "rx-frames-low", CMDL_S32, &coal_rx_frames_low_wanted, \ - &__ecoal.rx_max_coalesced_frames_low }, \ - { "tx-usecs-low", CMDL_S32, &coal_tx_usec_low_wanted, \ - &__ecoal.tx_coalesce_usecs_low }, \ - { "tx-frames-low", CMDL_S32, &coal_tx_frames_low_wanted, \ - &__ecoal.tx_max_coalesced_frames_low }, \ - { "rx-usecs-high", CMDL_S32, &coal_rx_usec_high_wanted, \ - &__ecoal.rx_coalesce_usecs_high }, \ - { "rx-frames-high", CMDL_S32, &coal_rx_frames_high_wanted, \ - &__ecoal.rx_max_coalesced_frames_high }, \ - { "tx-usecs-high", CMDL_S32, &coal_tx_usec_high_wanted, \ - &__ecoal.tx_coalesce_usecs_high }, \ - { "tx-frames-high", CMDL_S32, &coal_tx_frames_high_wanted, \ - &__ecoal.tx_max_coalesced_frames_high }, \ + { \ + .name = "adaptive-rx", \ + .type = CMDL_BOOL, \ + .wanted_val = &coal_adaptive_rx_wanted, \ + .ioctl_val = &__ecoal.use_adaptive_rx_coalesce, \ + }, \ + { \ + .name = "adaptive-tx", \ + .type = CMDL_BOOL, \ + .wanted_val = &coal_adaptive_tx_wanted, \ + .ioctl_val = &__ecoal.use_adaptive_tx_coalesce, \ + }, \ + { \ + .name = "sample-interval", \ + .type = CMDL_S32, \ + .wanted_val = &coal_sample_rate_wanted, \ + .ioctl_val = &__ecoal.rate_sample_interval, \ + }, \ + { \ + .name = "stats-block-usecs", \ + .type = CMDL_S32, \ + .wanted_val = &coal_stats_wanted, \ + .ioctl_val = &__ecoal.stats_block_coalesce_usecs, \ + }, \ + { \ + .name = "pkt-rate-low", \ + .type = CMDL_S32, \ + .wanted_val = &coal_pkt_rate_low_wanted, \ + .ioctl_val = &__ecoal.pkt_rate_low, \ + }, \ + { \ + .name = "pkt-rate-high", \ + .type = CMDL_S32, \ + .wanted_val = &coal_pkt_rate_high_wanted, \ + .ioctl_val = &__ecoal.pkt_rate_high, \ + }, \ + { \ + .name = "rx-usecs", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_usec_wanted, \ + .ioctl_val = &__ecoal.rx_coalesce_usecs, \ + }, \ + { \ + .name = "rx-frames", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_frames_wanted, \ + .ioctl_val = &__ecoal.rx_max_coalesced_frames, \ + }, \ + { \ + .name = "rx-usecs-irq", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_usec_irq_wanted, \ + .ioctl_val = &__ecoal.rx_coalesce_usecs_irq, \ + }, \ + { \ + .name = "rx-frames-irq", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_frames_irq_wanted, \ + .ioctl_val = &__ecoal.rx_max_coalesced_frames_irq, \ + }, \ + { \ + .name = "tx-usecs", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_usec_wanted, \ + .ioctl_val = &__ecoal.tx_coalesce_usecs, \ + }, \ + { \ + .name = "tx-frames", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_frames_wanted, \ + .ioctl_val = &__ecoal.tx_max_coalesced_frames, \ + }, \ + { \ + .name = "tx-usecs-irq", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_usec_irq_wanted, \ + .ioctl_val = &__ecoal.tx_coalesce_usecs_irq, \ + }, \ + { \ + .name = "tx-frames-irq", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_frames_irq_wanted, \ + .ioctl_val = &__ecoal.tx_max_coalesced_frames_irq, \ + }, \ + { \ + .name = "rx-usecs-low", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_usec_low_wanted, \ + .ioctl_val = &__ecoal.rx_coalesce_usecs_low, \ + }, \ + { \ + .name = "rx-frames-low", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_frames_low_wanted, \ + .ioctl_val = &__ecoal.rx_max_coalesced_frames_low, \ + }, \ + { \ + .name = "tx-usecs-low", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_usec_low_wanted, \ + .ioctl_val = &__ecoal.tx_coalesce_usecs_low, \ + }, \ + { \ + .name = "tx-frames-low", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_frames_low_wanted, \ + .ioctl_val = &__ecoal.tx_max_coalesced_frames_low, \ + }, \ + { \ + .name = "rx-usecs-high", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_usec_high_wanted, \ + .ioctl_val = &__ecoal.rx_coalesce_usecs_high, \ + }, \ + { \ + .name = "rx-frames-high", \ + .type = CMDL_S32, \ + .wanted_val = &coal_rx_frames_high_wanted, \ + .ioctl_val = &__ecoal.rx_max_coalesced_frames_high,\ + }, \ + { \ + .name = "tx-usecs-high", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_usec_high_wanted, \ + .ioctl_val = &__ecoal.tx_coalesce_usecs_high, \ + }, \ + { \ + .name = "tx-frames-high", \ + .type = CMDL_S32, \ + .wanted_val = &coal_tx_frames_high_wanted, \ + .ioctl_val = &__ecoal.tx_max_coalesced_frames_high,\ + }, \ } static int do_scoalesce(struct cmd_context *ctx) @@ -3090,9 +3228,21 @@ static int do_gregs(struct cmd_context *ctx) int gregs_dump_hex = 0; char *gregs_dump_file = NULL; struct cmdline_info cmdline_gregs[] = { - { "raw", CMDL_BOOL, &gregs_dump_raw, NULL }, - { "hex", CMDL_BOOL, &gregs_dump_hex, NULL }, - { "file", CMDL_STR, &gregs_dump_file, NULL }, + { + .name = "raw", + .type = CMDL_BOOL, + .wanted_val = &gregs_dump_raw, + }, + { + .name = "hex", + .type = CMDL_BOOL, + .wanted_val = &gregs_dump_hex, + }, + { + .name = "file", + .type = CMDL_STR, + .wanted_val = &gregs_dump_file, + }, }; int err; struct ethtool_drvinfo drvinfo; @@ -3189,10 +3339,22 @@ static int do_geeprom(struct cmd_context *ctx) u32 geeprom_length = 0; int geeprom_length_seen = 0; struct cmdline_info cmdline_geeprom[] = { - { "offset", CMDL_U32, &geeprom_offset, NULL }, - { "length", CMDL_U32, &geeprom_length, NULL, - 0, &geeprom_length_seen }, - { "raw", CMDL_BOOL, &geeprom_dump_raw, NULL }, + { + .name = "offset", + .type = CMDL_U32, + .wanted_val = &geeprom_offset, + }, + { + .name = "length", + .type = CMDL_U32, + .wanted_val = &geeprom_length, + .seen_val = &geeprom_length_seen, + }, + { + .name = "raw", + .type = CMDL_BOOL, + .wanted_val = &geeprom_dump_raw, + }, }; int err; struct ethtool_drvinfo drvinfo; @@ -3244,12 +3406,28 @@ static int do_seeprom(struct cmd_context *ctx) int seeprom_length_seen = 0; int seeprom_value_seen = 0; struct cmdline_info cmdline_seeprom[] = { - { "magic", CMDL_U32, &seeprom_magic, NULL }, - { "offset", CMDL_U32, &seeprom_offset, NULL }, - { "length", CMDL_U32, &seeprom_length, NULL, - 0, &seeprom_length_seen }, - { "value", CMDL_U8, &seeprom_value, NULL, - 0, &seeprom_value_seen }, + { + .name = "magic", + .type = CMDL_U32, + .wanted_val = &seeprom_magic, + }, + { + .name = "offset", + .type = CMDL_U32, + .wanted_val = &seeprom_offset, + }, + { + .name = "length", + .type = CMDL_U32, + .wanted_val = &seeprom_length, + .seen_val = &seeprom_length_seen, + }, + { + .name = "value", + .type = CMDL_U8, + .wanted_val = &seeprom_value, + .seen_val = &seeprom_value_seen, + }, }; int err; struct ethtool_drvinfo drvinfo; @@ -4553,11 +4731,27 @@ static int do_getmodule(struct cmd_context *ctx) int err; struct cmdline_info cmdline_geeprom[] = { - { "offset", CMDL_U32, &geeprom_offset, NULL }, - { "length", CMDL_U32, &geeprom_length, NULL, - 0, &geeprom_length_seen }, - { "raw", CMDL_BOOL, &geeprom_dump_raw, NULL }, - { "hex", CMDL_BOOL, &geeprom_dump_hex, NULL }, + { + .name = "offset", + .type = CMDL_U32, + .wanted_val = &geeprom_offset, + }, + { + .name = "length", + .type = CMDL_U32, + .wanted_val = &geeprom_length, + .seen_val = &geeprom_length_seen, + }, + { + .name = "raw", + .type = CMDL_BOOL, + .wanted_val = &geeprom_dump_raw, + }, + { + .name = "hex", + .type = CMDL_BOOL, + .wanted_val = &geeprom_dump_hex, + }, }; parse_generic_cmdline(ctx, &geeprom_changed, @@ -4669,10 +4863,30 @@ static int do_seee(struct cmd_context *ctx) int change = -1, change2 = 0; struct ethtool_eee eeecmd; struct cmdline_info cmdline_eee[] = { - { "advertise", CMDL_U32, &adv_c, &eeecmd.advertised }, - { "tx-lpi", CMDL_BOOL, &lpi_c, &eeecmd.tx_lpi_enabled }, - { "tx-timer", CMDL_U32, &lpi_time_c, &eeecmd.tx_lpi_timer}, - { "eee", CMDL_BOOL, &eee_c, &eeecmd.eee_enabled}, + { + .name = "advertise", + .type = CMDL_U32, + .wanted_val = &adv_c, + .ioctl_val = &eeecmd.advertised, + }, + { + .name = "tx-lpi", + .type = CMDL_BOOL, + .wanted_val = &lpi_c, + .ioctl_val = &eeecmd.tx_lpi_enabled, + }, + { + .name = "tx-timer", + .type = CMDL_U32, + .wanted_val = &lpi_time_c, + .ioctl_val = &eeecmd.tx_lpi_timer, + }, + { + .name = "eee", + .type = CMDL_BOOL, + .wanted_val = &eee_c, + .ioctl_val = &eeecmd.eee_enabled, + }, }; if (ctx->argc == 0)