From patchwork Mon Jun 5 18:46:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13267881 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 D374E168C6 for ; Mon, 5 Jun 2023 18:46:46 +0000 (UTC) Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 952B810B for ; Mon, 5 Jun 2023 11:46:44 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-33b4b70693eso26490665ab.1 for ; Mon, 05 Jun 2023 11:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1685990804; x=1688582804; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0eV7emip4/OL979iQf+sKnIXvJMh6a9u6EIROving2A=; b=BvFjCaAwh/jOkXg9rTTTtFgV27s6/RhV3K4LGKQefXUoFnclPZsW4LFONpM3tBIehn 7Qq4k9GY6+zHxK8z5grJrLSLNELSeSfvzLQOZII324NKzm5ITY1WG/JzhFD7HY1XcBzG R53qxf/Bray/zGrxHzdK79kWgsk7M57DtqHfA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685990804; x=1688582804; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0eV7emip4/OL979iQf+sKnIXvJMh6a9u6EIROving2A=; b=jVlOfcAFmRvNLchTwE+q083r/wHMFz/rbtjqvNXFkvWIF20l50vnv22kEKJqyohghw L+hJdf7o+YijuXqTLU/mtb2WKyMC/ih2L4ZE5CdQeSx+/naObIqp1CA+41vDUfNvTsta oV5vjv6WXJZUEu6Z6uRfTfEv6AqsUkKxIFxTMIkWoyAAIp273mJadlNNABhxv013m9Y+ MtWYHzB1uQMIHR4koY12y68iuwNWY6QS7iVkeqi+oMkHQXRs5u0GY18vHxZT+wt/VHe+ KSBNBck7UiYbLx3vbPEhydSP10iKZ6rdYs6V28fGHZqBdG59g/BQQ0ZL6MNdUjq5rl8i Xrrw== X-Gm-Message-State: AC+VfDwTVexRL29Rcfs9iistV9GUZG/jfnUDmZ4oBOd5wXFBiWu/Zd4W s0tOFcU2CkwdOMWGCSJpoe0Xt1mn9eslbysi5iNqXuVqP5B1T62IuSbhQQcCYP7vxEShnxWrMMr TfH6UxuZ/c4HJwOMnyfS1Hruf8+czu12I/Cc8quOi/QS/BSJKTwb8VprdA0AgbtEoxi/OpMKcYn lkzQo= X-Google-Smtp-Source: ACHHUZ690bbIvc0JKSoxehMJRBnXxarOaoYLoJEmz3fTK/RCZGyqiukS53C9OfzHLB5qWAPtH6kJHw== X-Received: by 2002:a92:dc8c:0:b0:339:f011:77f5 with SMTP id c12-20020a92dc8c000000b00339f01177f5mr640978iln.12.1685990803647; Mon, 05 Jun 2023 11:46:43 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id 72-20020a63034b000000b005344b30d449sm6140831pgd.86.2023.06.05.11.46.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Jun 2023 11:46:43 -0700 (PDT) From: Justin Chen To: netdev@vger.kernel.org Cc: simon.horman@corigine.com, Justin Chen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Daniil Tatianin , Marco Bonelli , Gal Pressman , Jiri Pirko , Sean Anderson , Vincent Mailhol , Kuniyuki Iwashima , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next] ethtool: ioctl: improve error checking for set_wol Date: Mon, 5 Jun 2023 11:46:16 -0700 Message-Id: <1685990778-34039-1-git-send-email-justin.chen@broadcom.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.0 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 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. Reviewed-by: Simon Horman Signed-off-by: Justin Chen --- 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;