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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 5C09EC433C1 for ; Tue, 23 Mar 2021 00:55:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1ED69619A9 for ; Tue, 23 Mar 2021 00:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231404AbhCWAzK (ORCPT ); Mon, 22 Mar 2021 20:55:10 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:41970 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231180AbhCWAyf (ORCPT ); Mon, 22 Mar 2021 20:54:35 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1lOVJW-00CVJm-4n; Tue, 23 Mar 2021 01:54:30 +0100 Date: Tue, 23 Mar 2021 01:54:30 +0100 From: Andrew Lunn To: Moshe Shemesh Cc: "David S. Miller" , Jakub Kicinski , Adrian Pop , Michal Kubecek , Don Bollinger , netdev@vger.kernel.org, Vladyslav Tarasiuk Subject: Re: [RFC PATCH V4 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data Message-ID: References: <1616433075-27051-1-git-send-email-moshe@nvidia.com> <1616433075-27051-2-git-send-email-moshe@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1616433075-27051-2-git-send-email-moshe@nvidia.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org > +static int eeprom_prepare_data(const struct ethnl_req_info *req_base, > + struct ethnl_reply_data *reply_base, > + struct genl_info *info) > +{ > + struct eeprom_reply_data *reply = MODULE_EEPROM_REPDATA(reply_base); > + struct eeprom_req_info *request = MODULE_EEPROM_REQINFO(req_base); > + struct ethtool_module_eeprom page_data = {0}; > + struct net_device *dev = reply_base->dev; > + int ret; > + > + if (!dev->ethtool_ops->get_module_eeprom_by_page) > + return -EOPNOTSUPP; > + > + /* Allow dumps either of low or high page without crossing half page boundary */ > + if ((request->offset < ETH_MODULE_EEPROM_PAGE_LEN / 2 && > + request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN / 2) || > + request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) > + return -EINVAL; Please keep all the parameter validation together, in eeprom_parse_request(). At some point, we may extend eeprom_parse_request() to make use of extack, to indicate which parameter is invalid. Just getting an -EINVAL can be hard to debug, where as NL_SET_ERR_MSG_ATTR() can help the user. Andrew