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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT 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 6EF1FC169C4 for ; Mon, 11 Feb 2019 10:38:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 287A12084D for ; Mon, 11 Feb 2019 10:38:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="X5Ylc99Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726892AbfBKKi2 (ORCPT ); Mon, 11 Feb 2019 05:38:28 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52653 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfBKKi2 (ORCPT ); Mon, 11 Feb 2019 05:38:28 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so16808033wml.2 for ; Mon, 11 Feb 2019 02:38:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=BQVR4qMtRntFcEg4cppuh3bwzMik7plD3jIQUmLaB8U=; b=X5Ylc99YYVQ6RDs8GP9fVoOH5/MYeQr7N4iobaWjzqHdrqMRZXaMyvRaHMoXeBjf8e GSsZS5qCJhW2V6mjbfRftZ7F4I5OKvJcBmTtpiP28g8XPESBB/ax5vrHBMUpZ5F9IJw5 HvmrpQF+EiYkspCSalTU/BqEN98V7lqcBQ/zD2ErJFReqtocjp8nefE0Eck7tLhn48Lf vaXDjT7fLdAJ+YqsfPOECHuJH2X3qcZygCtq213I6mq4ZfNYm7HtQfEwaDf9D5AVxM5s cEJYlIe9xiAFt9z4KY3yR2aZPF6jGGn4GTWzn5775JHf8EBhkl+12l58OWvS0JyDhWpA 6pLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=BQVR4qMtRntFcEg4cppuh3bwzMik7plD3jIQUmLaB8U=; b=suOK6fuGZJTjw+C2gsMKO5bSCVKKHUk2VHTjZSh+3uJrTlMp2AxCiTuRj/q2RELyvp kYX1Dee7100etvYKM9FbVkonMCIY4/tHc6Rn8homEwwl9NPcurWfABFQJpL2WsA8r+iS xTXlcVJ396hOT/XMEpGOYkL0OEBcM4W217f5zASJjacfNj6Gjn5KH67Cxf6ol3FsH0RS ZiqgXPm1Bfas4/PoXJo+IiHz732eel7LGbF+esHP1rQZchKjnyMktJ5iZLc9N/3J8aaA iuODMu4iO2CgBVwohwy4uDNAUajkSXoSBYrUvkS7ElNcwDjzKySB2rMDu0dAaZbZyk5y 8NSA== X-Gm-Message-State: AHQUAuZXY7+bpSho+4E+Tmupok5fmoi+r5BdezsSkpbpkI3nA/1zi8z4 dTZJmnqQNmk8CFo//ITX4HIjaA== X-Google-Smtp-Source: AHgI3Iak0kHsu/N+7UGj4pZ49eKter4Oqf6Pl8M7XO8VVuRLqoTTHxWbvFVzn+GhRUTUhjpw2lqfGw== X-Received: by 2002:a1c:6707:: with SMTP id b7mr8774422wmc.138.1549881506912; Mon, 11 Feb 2019 02:38:26 -0800 (PST) Received: from localhost (mail.chocen-mesto.cz. [85.163.43.2]) by smtp.gmail.com with ESMTPSA id t63sm9121382wmt.8.2019.02.11.02.38.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Feb 2019 02:38:26 -0800 (PST) Date: Mon, 11 Feb 2019 11:29:03 +0100 From: Jiri Pirko To: Aya Levin Cc: David Ahern , netdev@vger.kernel.org, "David S. Miller" , Jiri Pirko , Moshe Shemesh , Eran Ben Elisha , Tal Alon , Ariel Almog Subject: Re: [PATCH for-next 1/4] devlink: refactor validation of finding required arguments Message-ID: <20190211102903.GA2251@nanopsycho> References: <1549532202-943-1-git-send-email-eranbe@mellanox.com> <1549823329-10377-1-git-send-email-ayal@mellanox.com> <1549823329-10377-2-git-send-email-ayal@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1549823329-10377-2-git-send-email-ayal@mellanox.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Sun, Feb 10, 2019 at 07:28:46PM CET, ayal@mellanox.com wrote: >Introducing argument's metadata structure matching a bitmap flag per >required argument and an error message if missing. Using this static >array to refactor validation of finding required arguments in devlink >command line and to ease further maintenance. > >Signed-off-by: Aya Levin >Reviewed-by: Moshe Shemesh >--- > devlink/devlink.c | 155 +++++++++++++++++------------------------------------- > 1 file changed, 47 insertions(+), 108 deletions(-) > >diff --git a/devlink/devlink.c b/devlink/devlink.c >index d823512a4030..a05755385a49 100644 >--- a/devlink/devlink.c >+++ b/devlink/devlink.c >@@ -39,6 +39,7 @@ > #define PARAM_CMODE_RUNTIME_STR "runtime" > #define PARAM_CMODE_DRIVERINIT_STR "driverinit" > #define PARAM_CMODE_PERMANENT_STR "permanent" >+#define DL_ARGS_REQUIRED_MAX_ERR_LEN 80 > > static int g_new_line_count; > >@@ -950,6 +951,51 @@ static int param_cmode_get(const char *cmodestr, > return 0; > } > >+struct dl_args_metadata { >+ uint32_t o_flag; >+ char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN]; >+}; >+ >+static const struct dl_args_metadata dl_args_required[] = { >+ {DL_OPT_PORT_TYPE, "Port type not set.\n"}, >+ {DL_OPT_PORT_COUNT, "Port split count option expected.\n"}, >+ {DL_OPT_SB_POOL, "Pool index option expected.\n"}, >+ {DL_OPT_SB_SIZE, "Pool size option expected.\n"}, >+ {DL_OPT_SB_TYPE, "Pool type option expected.\n"}, >+ {DL_OPT_SB_THTYPE, "Pool threshold type option expected.\n"}, >+ {DL_OPT_SB_TH, "Threshold option expected.\n"}, >+ {DL_OPT_SB_TC, "TC index option expected.\n"}, >+ {DL_OPT_ESWITCH_MODE, "E-Switch mode option expected.\n"}, >+ {DL_OPT_ESWITCH_INLINE_MODE, "E-Switch inline-mode option expected.\n"}, >+ {DL_OPT_DPIPE_TABLE_NAME, "Dpipe table name expected\n"}, >+ {DL_OPT_DPIPE_TABLE_COUNTERS, "Dpipe table counter state expected\n"}, >+ {DL_OPT_ESWITCH_ENCAP_MODE, "E-Switch encapsulation option expected.\n"}, >+ {DL_OPT_PARAM_NAME, "Parameter name expected.\n"}, >+ {DL_OPT_PARAM_VALUE, "Value to set expected.\n"}, >+ {DL_OPT_PARAM_CMODE, "Configuration mode expected.\n"}, >+ {DL_OPT_REGION_SNAPSHOT_ID, "Region snapshot id expected.\n"}, >+ {DL_OPT_REGION_ADDRESS, "Region address value expected.\n"}, >+ {DL_OPT_REGION_LENGTH, "Region length value expected.\n"}, Remove the "\n" from there and put it to the pr_err() call. >+}; >+ >+static int validate_finding_required_dl_args(uint32_t o_required, Please maintain the current naming scheme of functions. This should be named something like: dl_args_finding_required_validate() >+ uint32_t o_found) >+{ >+ uint32_t dl_args_required_size; >+ uint32_t o_flag; >+ int i; >+ >+ dl_args_required_size = ARRAY_SIZE(dl_args_required); >+ for (i = 0; i < dl_args_required_size; i++) { >+ o_flag = dl_args_required[i].o_flag; >+ if ((o_required & o_flag) && !(o_found & o_flag)) { >+ pr_err("%s", dl_args_required[i].err_msg); >+ return -EINVAL; >+ } >+ } >+ return 0; >+} >+ [...]