From nobody Fri Sep 5 20:00:51 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B82BC49EC3 for ; Tue, 23 Aug 2022 11:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357893AbiHWLVW (ORCPT ); Tue, 23 Aug 2022 07:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357933AbiHWLR2 (ORCPT ); Tue, 23 Aug 2022 07:17:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48DEA804B5; Tue, 23 Aug 2022 02:20:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A3654B81C86; Tue, 23 Aug 2022 09:20:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E67B9C433C1; Tue, 23 Aug 2022 09:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246449; bh=5Eg+mOfgK0nOXc2WZG4g5gtNOFCOyYxaBjt1GGpN1z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AhxuFO/nz1iaXFbM0zl4z6lSZySlO4YcfSV0ShOdYL/79FJzSD15VPWZkMd2k/ZUa iknTSxel9Hv4s6JzQySTRVf2As4O/bDWyHfLIJu07MsjlCgi9ncuKE0flw9VsH23BO WsWgzL5ziO9PSR0AErz6BMDK/eE6hX5v9vr9oDy4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Kalle Valo , Sasha Levin Subject: [PATCH 5.4 096/389] wifi: rtlwifi: fix error codes in rtl_debugfs_set_write_h2c() Date: Tue, 23 Aug 2022 10:22:54 +0200 Message-Id: <20220823080119.622749193@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dan Carpenter [ Upstream commit b88d28146c30a8e14f0f012d56ebf19b68a348f4 ] If the copy_from_user() fails or the user gives invalid date then the correct thing to do is to return a negative error code. (Currently it returns success). I made a copy additional related cleanups: 1) There is no need to check "buffer" for NULL. That's handled by copy_from_user(). 2) The "h2c_len" variable cannot be negative because it is unsigned and because sscanf() does not return negative error codes. Fixes: 610247f46feb ("rtlwifi: Improve debugging by using debugfs") Signed-off-by: Dan Carpenter Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/YoOLnDkHgVltyXK7@kili Signed-off-by: Sasha Levin --- drivers/net/wireless/realtek/rtlwifi/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/debug.c b/drivers/net/wir= eless/realtek/rtlwifi/debug.c index 55db71c766fe..ec0da33da4f8 100644 --- a/drivers/net/wireless/realtek/rtlwifi/debug.c +++ b/drivers/net/wireless/realtek/rtlwifi/debug.c @@ -349,8 +349,8 @@ static ssize_t rtl_debugfs_set_write_h2c(struct file *f= ilp, =20 tmp_len =3D (count > sizeof(tmp) - 1 ? sizeof(tmp) - 1 : count); =20 - if (!buffer || copy_from_user(tmp, buffer, tmp_len)) - return count; + if (copy_from_user(tmp, buffer, tmp_len)) + return -EFAULT; =20 tmp[tmp_len] =3D '\0'; =20 @@ -360,8 +360,8 @@ static ssize_t rtl_debugfs_set_write_h2c(struct file *f= ilp, &h2c_data[4], &h2c_data[5], &h2c_data[6], &h2c_data[7]); =20 - if (h2c_len <=3D 0) - return count; + if (h2c_len =3D=3D 0) + return -EINVAL; =20 for (i =3D 0; i < h2c_len; i++) h2c_data_packed[i] =3D (u8)h2c_data[i]; --=20 2.35.1