From patchwork Wed May 31 20:53:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13262592 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76C2A1640F for ; Wed, 31 May 2023 20:54:01 +0000 (UTC) Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49F2B12C for ; Wed, 31 May 2023 13:54:00 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64d5b4c400fso224667b3a.1 for ; Wed, 31 May 2023 13:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1685566439; x=1688158439; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pB/lx5c6WaBVuh62Y+hiNIjrnopqoE7DOl+7kc6jf6U=; b=UQZh4iC+dijnQfBbRdt95kWEXwhnXwAuvuIybiFX8waoFHUM/8mkVicTKfynXl+vXM GXYhAU5fkF699/ArUEckUcyfkuzfShFe/cU3A3YLJCDJeqKhW77H6sYyDTgeQSZE12m1 1ZtxZjH8xVAbrZ79lAzIhC1tO27wv9bPCVExE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685566439; x=1688158439; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pB/lx5c6WaBVuh62Y+hiNIjrnopqoE7DOl+7kc6jf6U=; b=ks8PsF5jbYNH3hkw2rYhAfbIJWDLAq+gK+sW9Sp3kTPC5QghMw3F3cPVjD1HLb5RXc egI8yfypFWxK42SaBPExLWJTTiVRu0tBHIKmcaa6lR90aQpaYP2TplkjMWMWOdyfIakZ 1JQ8QN4VHc1EF8vCvAjQ17tysuzLQXE9AAiJKHHPk0vmjn3OoPqWEbC5Nl1SpZg8cNi9 bY2g9zkX9xc3H19Fr59JTQbs9fqn5E+Gr/wyA0SmIvzqI7s6JoC/qhwpN4ZXIekdFDAX oP2ASp7WCQk94LxR6oZNjfxdVMoCfOBruDxGteB1NGl0RSizQ5ri2N1fL+RzQTPkEGAN r7Fw== X-Gm-Message-State: AC+VfDw45XDx5rxgJwitucA9PoNW9QGExKX46KvI0y/zLX+6cpN1I4Q0 rUgpAHz2GJYOaz0wHWPNjEr5vcbAtJo/VPOSbPTzE1RM+cUyhxIvyR1vEAsh9m88z/bG/yUhwWN sqChIJgW4QDzSOJ05iFapuAOXoDVsluCDvBk5aj/FF4b0sbAORb6jGw0KpkW6//xxpS7h1/RlAU NyYvI= X-Google-Smtp-Source: ACHHUZ435HMGZtkvWpKkQToZ0wFTxnJdVhDep9vOugI0fciQ9sfXq50qV6AeJGgB66wEdhvIvJ1o3A== X-Received: by 2002:a05:6a20:5494:b0:10c:8f0c:f81c with SMTP id i20-20020a056a20549400b0010c8f0cf81cmr8751822pzk.53.1685566439336; Wed, 31 May 2023 13:53:59 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id j8-20020a62e908000000b0064f97ff4506sm3155556pfh.68.2023.05.31.13.53.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2023 13:53:56 -0700 (PDT) From: Justin Chen To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: bcm-kernel-feedback-list@broadcom.com, florian.fainelli@broadcom.com, Justin Chen Subject: [PATCH net-next] ethtool: ioctl: improve error checking for set_wol Date: Wed, 31 May 2023 13:53:49 -0700 Message-Id: <1685566429-2869-1-git-send-email-justin.chen@broadcom.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, MIME_HEADER_CTYPE_ONLY,MIME_NO_TEXT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-Patchwork-Delegate: kuba@kernel.org The netlink version of set_wol checks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer. Signed-off-by: Justin Chen Reviewed-by: Simon Horman --- net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 6bb778e10461..80f456f83db0 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) { - struct ethtool_wolinfo wol; + struct ethtool_wolinfo wol, cur_wol; int ret; - if (!dev->ethtool_ops->set_wol) + if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) return -EOPNOTSUPP; + memset(&cur_wol, 0, sizeof(struct ethtool_wolinfo)); + cur_wol.cmd = ETHTOOL_GWOL; + dev->ethtool_ops->get_wol(dev, &cur_wol); + if (copy_from_user(&wol, useraddr, sizeof(wol))) return -EFAULT; + if (wol.wolopts & ~cur_wol.supported) + return -EOPNOTSUPP; + + if (wol.wolopts == cur_wol.wolopts) + return 0; + ret = dev->ethtool_ops->set_wol(dev, &wol); if (ret) return ret;