From patchwork Mon Apr 13 21:21:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 221229 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=-6.8 required=3.0 tests=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 89813C2BA2B for ; Mon, 13 Apr 2020 21:21:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DB8420663 for ; Mon, 13 Apr 2020 21:21:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388993AbgDMVV0 (ORCPT ); Mon, 13 Apr 2020 17:21:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:51744 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388978AbgDMVVZ (ORCPT ); Mon, 13 Apr 2020 17:21:25 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0F829AD4F; Mon, 13 Apr 2020 21:21:23 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 7D775E0FAD; Mon, 13 Apr 2020 23:21:20 +0200 (CEST) From: Michal Kubecek Subject: [PATCH ethtool] features: accept long legacy flag names when setting features To: John Linville Cc: netdev@vger.kernel.org, Konstantin Kharlamov Message-Id: <20200413212120.7D775E0FAD@unicorn.suse.cz> Date: Mon, 13 Apr 2020 23:21:20 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The legacy feature flags have long names (e.g. "generic-receive-offload") and short names (e.g. "gro"). While "ethtool -k" shows only long names, "ethtool -K" accepts only short names. This is a bit confusing as users have to resort to documentation to see what flag name to use; in particular, if a legacy flag corresponds to only one actual kernel feature, "ethtool -k" shows the output in the same form as if long flag name were a kernel feature name but this name cannot be used to set the flag/feature. Accept both short and long legacy flag names in "ethool -K". Reported-by: Konstantin Kharlamov Signed-off-by: Michal Kubecek --- ethtool.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ethtool.c b/ethtool.c index 1b4e08b6e60f..73f15b3912c1 100644 --- a/ethtool.c +++ b/ethtool.c @@ -2297,26 +2297,33 @@ static int do_sfeatures(struct cmd_context *ctx) /* Generate cmdline_info for legacy flags and kernel-named * features, and parse our arguments. */ - cmdline_features = calloc(ARRAY_SIZE(off_flag_def) + defs->n_features, + cmdline_features = calloc(2 * ARRAY_SIZE(off_flag_def) + + defs->n_features, sizeof(cmdline_features[0])); if (!cmdline_features) { perror("Cannot parse arguments"); rc = 1; goto err; } - for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) + j = 0; + for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) { flag_to_cmdline_info(off_flag_def[i].short_name, off_flag_def[i].value, &off_flags_wanted, &off_flags_mask, - &cmdline_features[i]); + &cmdline_features[j++]); + flag_to_cmdline_info(off_flag_def[i].long_name, + off_flag_def[i].value, + &off_flags_wanted, &off_flags_mask, + &cmdline_features[j++]); + } for (i = 0; i < defs->n_features; i++) flag_to_cmdline_info( defs->def[i].name, FEATURE_FIELD_FLAG(i), &FEATURE_WORD(efeatures->features, i, requested), &FEATURE_WORD(efeatures->features, i, valid), - &cmdline_features[ARRAY_SIZE(off_flag_def) + i]); + &cmdline_features[j++]); parse_generic_cmdline(ctx, &any_changed, cmdline_features, - ARRAY_SIZE(off_flag_def) + defs->n_features); + 2 * ARRAY_SIZE(off_flag_def) + defs->n_features); free(cmdline_features); if (!any_changed) {