From patchwork Sat Mar 25 08:34:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Chen X-Patchwork-Id: 74866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp297332vqo; Sat, 25 Mar 2023 02:21:33 -0700 (PDT) X-Google-Smtp-Source: AK7set/bgxLpwcg/UMskDmKVXPk8ciR+vX2f8c2zoWEmH8Hy1TrMMfXtjVsWFHr8OuPVgQMjMyhX X-Received: by 2002:a05:6a20:a82a:b0:da:5ef4:69f5 with SMTP id cb42-20020a056a20a82a00b000da5ef469f5mr4694302pzb.21.1679736093269; Sat, 25 Mar 2023 02:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679736093; cv=none; d=google.com; s=arc-20160816; b=UPRyq58SJWeJqhUJAi29eb3GoBpTbIZEilj+XBBxaXgkEx6LNldEI6S7x2Sjybg9jk zFPl73msiJiwRoZQ1vuBSY/9aAET816NivP8/aEcv7iHqIwQGLp57zSSgOblJZeL644W gDx82HDvscixzAa3XwtTkzzlVctD6lJtklwOiJ46s+KLjctBKgSx2uvZqKXErQ1Pf96p 8YK/4spQ48o/aTlQ9orbMRgD/NfptUSZbV0jrczcx3tEqa/1pwUQsJUsCD1kEZUh8z66 N1lDRtGHefYH+v6c5ayabntw8J+NJmhoIoixRe3s1VtlI8hv0/QWgr48aLCGKUlgXBQB 13Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=TC1VviM7kJDuwC/+3CMrSgl8Bi7rZU2Q6IqzYrz0DpI=; b=i6VwgE81W4QpkOT3Z7a50KzDwYXjpRqNgQK470x/hZXntt/XysqUfuWphbgb3s2VUE qvsLWYS2TlcKsVVG8KHtvP/bJ7al4d2i6kOh4+0uPLpkIjbCoGO7gWKH37TtImgdsbhe IviAa9LR/iWPFKeEUeZAUXJnJtiV/hi196eaF7fQTO/LRV7tIETWzDXgppue9TuAEPQt Pwq8mNPPxBO+CbVarvdlSB9vFyRajzoUfiF6ApruJpPII+hTym23Ow+1yO9CdaXjXCSl vQ06fE4cENBPFbqteRqDhtBHCopgy7o7x4wrIk9Yz2UC1SuVZWgtmRQOmsimkHZ8Cd45 COGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ghnvyg7a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020aa78422000000b005941ff7940dsi3361310pfn.203.2023.03.25.02.21.21; Sat, 25 Mar 2023 02:21:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ghnvyg7a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232063AbjCYIej (ORCPT + 99 others); Sat, 25 Mar 2023 04:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231704AbjCYIeh (ORCPT ); Sat, 25 Mar 2023 04:34:37 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2D9018173; Sat, 25 Mar 2023 01:34:36 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id f17so2927872oiw.10; Sat, 25 Mar 2023 01:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679733276; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TC1VviM7kJDuwC/+3CMrSgl8Bi7rZU2Q6IqzYrz0DpI=; b=Ghnvyg7aycOtgQ6MkB2h4AzEv+KZcO4mvdIb6sFX5SWQD5BGVTS4ogaOqpmBJQrHvh 50CPoyWg4Jp8PBqBdpougNl96VLCvzKEt/fw2Kw+miIMoFkjkNLYtEr3KCeiqupqC3kL 8eTlJBpkgbf1XGNrXDrfL3BQdwq7fl0+CQ3o2T1vvn7H2BHTldKBHfE7D6uhAyJIbnAZ Yxk+bi1GWICMu/0ER7T8BtqFyfmwvVpppo0l+O3dEuw9wxA/atEHsjptuCj0bgw4J4kW cJKg4gxHUPBQYtmtbYZLVDd54EOtxenO0crt+vgdRj7SDnqF6iE/n1spGN5m2vJHZg2F 0KHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679733276; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TC1VviM7kJDuwC/+3CMrSgl8Bi7rZU2Q6IqzYrz0DpI=; b=RHUUS39pX9K16D8lhC0KYLQAotSDYjDlcHCSirHzTFtNStsoyXdZvEOCZrjuSK7PwI GGJtnQ0MYFH80Eh5GtJxWycpmdV/PahDvCyh/EqIrBh/Dq08founZValBYHVP6PmbL0y dxUnOC8+7Xs9pNTwAX+L6ZOl2lJfoA2qnwIf34+Fxzs6DWlh2LdZx6GTBlNVwWnv3Q1x uSlmN5PuExa6E8MRxkZTUjfLrdhqaxma7DPcPa9UbMJ7NAd4ddgeIeNMTvNcz79w1jUn YV5qSR/l5GYmk6/N1I0xi/3oPth8VQ+EHLLuuf1PFtJopzG9zXKG5fXLrddYmctq9JQb hsrw== X-Gm-Message-State: AO0yUKUw5xkbQ8DLVWfhy7q6Q0Q/xbVqlHgGyffWI2ecEh1+MjhkPqhl rHk587OfMXvp3R1dNx/FRUY= X-Received: by 2002:aca:2102:0:b0:387:3a49:472b with SMTP id 2-20020aca2102000000b003873a49472bmr2513878oiz.19.1679733276216; Sat, 25 Mar 2023 01:34:36 -0700 (PDT) Received: from chcpu13.cse.ust.hk (191host119.mobilenet.cse.ust.hk. [143.89.191.119]) by smtp.gmail.com with ESMTPSA id u47-20020a4a8c32000000b0053bb2ae3a78sm2206173ooj.24.2023.03.25.01.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 01:34:35 -0700 (PDT) From: Wei Chen To: pkshih@realtek.com Cc: kvalo@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Chen Subject: [PATCH] wireless: rtlwifi: fix incorrect error codes in rtl_debugfs_set_write_rfreg() Date: Sat, 25 Mar 2023 08:34:29 +0000 Message-Id: <20230325083429.3571917-1-harperchen1110@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761330953981097196?= X-GMAIL-MSGID: =?utf-8?q?1761330953981097196?= If there is a failure during copy_from_user or user-provided data buffer is invalid, rtl_debugfs_set_write_rfreg should return negative error code instead of a positive value count. Fix this bug by returning correct error code. Moreover, the check of buffer against null is removed since it will be handled by copy_from_user. Signed-off-by: Wei Chen Reviewed-by: Simon Horman --- drivers/net/wireless/realtek/rtlwifi/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/debug.c b/drivers/net/wireless/realtek/rtlwifi/debug.c index 3e7f9b4f1f19..9eb26dfe4ca9 100644 --- a/drivers/net/wireless/realtek/rtlwifi/debug.c +++ b/drivers/net/wireless/realtek/rtlwifi/debug.c @@ -375,8 +375,8 @@ static ssize_t rtl_debugfs_set_write_rfreg(struct file *filp, tmp_len = (count > sizeof(tmp) - 1 ? sizeof(tmp) - 1 : count); - if (!buffer || copy_from_user(tmp, buffer, tmp_len)) - return count; + if (copy_from_user(tmp, buffer, tmp_len)) + return -EFAULT; tmp[tmp_len] = '\0'; @@ -386,7 +386,7 @@ static ssize_t rtl_debugfs_set_write_rfreg(struct file *filp, if (num != 4) { rtl_dbg(rtlpriv, COMP_ERR, DBG_DMESG, "Format is \n"); - return count; + return -EINVAL; } rtl_set_rfreg(hw, path, addr, bitmask, data);