From patchwork Sun Mar 26 05:42:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Chen X-Patchwork-Id: 75014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp782214vqo; Sat, 25 Mar 2023 23:21:55 -0700 (PDT) X-Google-Smtp-Source: AK7set9Cd5H5tGDKq+HCaVvkXDeHj9v1WWuaRQ4efkVsuoBwwH6+V1se3SGrS84889RHtATLs8SH X-Received: by 2002:a05:6a20:a905:b0:d9:e1b:652b with SMTP id cd5-20020a056a20a90500b000d90e1b652bmr7566560pzb.59.1679811715580; Sat, 25 Mar 2023 23:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679811715; cv=none; d=google.com; s=arc-20160816; b=pjeJ42TkcNHlDsJA7MM9ZOVEPvLek0VjmZ0vzhhcbr48bAJhm2Canq/8BEjo0Y0MUh Whms68COr/Wha6dQiPg9D8tRVx95IlpzIvbcqETRjvxCSMmhbKtMkXxUbTlbe0vhSzmP UClpYvS00he8CFXi9Ng3NxdWaMwDPAuNJVLn4S4sERkw8HRzH9D8KKoOWdEnPwJNgiL1 2aZJVgcdMr+PyjV3qzrapHUEgZ+6QAyyVh9dA8H9jCXqPJalJ3C6q1vWWooaq25Lm3qK 0FPAvQgukgD/qsEHL/uG/TgcFAvSXAOorrk4NhPM0wYofk0bGRZBNj7/DdNeOmPAeJvS 4EzQ== 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=jH04qlqfc5qBZQ1rXFayew5ai68aCN4IVs+pY06TudM=; b=P7XVAr7Hw3fvLET+C11aMcgERVGLsGGpW0VmusiteRg8HwXA+lXVhV1FxW0ROYnaVz vWEk3ykIOrKcqG+9+OdU/hA8rN4QKBr8ZbiVl6YPhx4FNY+fTEXXU84uAawG8RIU+Igx dLv6fQx/NQ0R0tEQKmtuTpP+obphc6JYciIBlsZiWt+RuGBlo0FXJQg0X6+bacvwYmpZ 5BFeiD5/Xnbi4jOv5Df+z5u9d1J+7e0dvVXcTz9l5gouA/yFxYO74hOmLSLsFu/nMwuE OcrsQrUUI8biKjFwdijrX0xXpD7Qa0C5uUxN6IrYuamSJRCkRGt/ix4Cvg29Epf+mrsN /nXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jce2BQZ4; 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 x5-20020a654145000000b004fbb899417dsi23733680pgp.851.2023.03.25.23.21.43; Sat, 25 Mar 2023 23:21:55 -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=jce2BQZ4; 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 S231842AbjCZFm1 (ORCPT + 99 others); Sun, 26 Mar 2023 01:42:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbjCZFm0 (ORCPT ); Sun, 26 Mar 2023 01:42:26 -0400 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDD5449C; Sat, 25 Mar 2023 22:42:24 -0700 (PDT) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-17683b570b8so6034143fac.13; Sat, 25 Mar 2023 22:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679809344; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jH04qlqfc5qBZQ1rXFayew5ai68aCN4IVs+pY06TudM=; b=jce2BQZ4MjDiuRhthqYApKhiu+noOV1VnPDF4JVwB7MYEJ3+KPUcPBcSECou7kcWnS tb6JdW9lY7evJ2UNTwcdeXkGoAaHUL6ieOMWB+0YDrpEeX37I4IRlDl3D2DnzdiyKJFm T3ZZVFY23cvFxtZNG578sTxA8ikU5/O3ozglbidCtoPkknOal9mISE5NT5elGx2EKNoO idktaojTJq6DGO81hAJUDGlM2fTa3f3Q4pNm7KpWjYPBTHmg90tvxmVP/Yp8oO6XSH9x W54BC6+g+koeuaaZChObNfTaKIdZKdFVnlzuVi5TvC9jn7AzV5fliKVKhl4UkXrqBAlE v0Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679809344; 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=jH04qlqfc5qBZQ1rXFayew5ai68aCN4IVs+pY06TudM=; b=aQb4marxQt8UguTOwp7KcAlcKkhyLlu9miuDCB6DDahSsk4AOVFuiRVVO5/fMG38im H12NRSRuy5ceBYbR1ke+SGSiVCAv7E9khDs5k1kLQPwcEg3Lna+SkJoEUZfGjdEbDqrJ 2J3xOY90UJKDdNwh+X+MwPGrfGyXE6QgorRPNXYoNF2ovt5LyESgY7MTWlfewTGbRybZ aAgmyB+PXW2R9oXTeOuJTX6O2KxbqwucW0aAWhBAGJeGxCZ4Ul8QjGyIrc0f2JA6THfX 0oy0tnKZ1sn04WO9NpIfKXdQUHJGgnyi2r9GED8xtMkiREicQUoOnLzITZ7HkcAcj1LG yo+w== X-Gm-Message-State: AAQBX9dHyJmIZ/+Rgtxy+7HG3NG26X84qUphqqBdOqdQJGul6DxnJqtw jP5d3X6wG/aU0+NZ9kmeSzw= X-Received: by 2002:a05:6870:210f:b0:17a:cc85:5b1e with SMTP id f15-20020a056870210f00b0017acc855b1emr5249207oae.3.1679809344303; Sat, 25 Mar 2023 22:42:24 -0700 (PDT) Received: from chcpu13.cse.ust.hk (191host119.mobilenet.cse.ust.hk. [143.89.191.119]) by smtp.gmail.com with ESMTPSA id w14-20020a056870b38e00b001723f29f6e2sm8820827oap.37.2023.03.25.22.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 22:42:23 -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 v2] rtlwifi: fix incorrect error codes in rtl_debugfs_set_write_reg() Date: Sun, 26 Mar 2023 05:42:17 +0000 Message-Id: <20230326054217.93492-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?1761410249103115122?= X-GMAIL-MSGID: =?utf-8?q?1761410249103115122?= If there is a failure during copy_from_user or user-provided data buffer is invalid, rtl_debugfs_set_write_reg 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. Fixes: 610247f46feb ("rtlwifi: Improve debugging by using debugfs") Signed-off-by: Wei Chen Reviewed-by: Simon Horman --- Changes in v2: - Add fixes commit tag - Correct the subject prefix 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 0b1bc04cb6ad..3e7f9b4f1f19 100644 --- a/drivers/net/wireless/realtek/rtlwifi/debug.c +++ b/drivers/net/wireless/realtek/rtlwifi/debug.c @@ -278,8 +278,8 @@ static ssize_t rtl_debugfs_set_write_reg(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'; @@ -287,7 +287,7 @@ static ssize_t rtl_debugfs_set_write_reg(struct file *filp, num = sscanf(tmp, "%x %x %x", &addr, &val, &len); if (num != 3) - return count; + return -EINVAL; switch (len) { case 1: