From patchwork Mon Dec 2 03:19:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xueqin Luo X-Patchwork-Id: 13889921 X-Patchwork-Delegate: nbd@nbd.name Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB56E70805; Mon, 2 Dec 2024 03:19:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733109597; cv=none; b=prgvDSizveEFYhiabsdT2qVq44ie/LYhm3NTTRntnw/wW/ORAQl7q3jaV5c///bRLf2Gk3sw1oeRiZfr8Jval2KG8CRulwz/cCJgCOxIouqhr0J1f1BtveXIzdJy7mlWz2cKNJR4CidRNdB/iri5i/draYeRL0ev+g5bKtfAcMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733109597; c=relaxed/simple; bh=Nl0cH3ole0xzuAuTHOhtcuqlHx62T9z7X863QnqDIWM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hJTVx3Kov5FpW1fGKbfEQNiKKeHGfhZycDlm92/nAUwLXTFm/DDSOLYtrmt/bVmBSKqN8ynmRNW/Kp8tR2TktP1/Z2pDxkec+BAAZVYukI7YLm/BUvJeBmP11jnYVyvJSeWwUF16c7imKa0f/+JIc5Ho81s5QwdL/dMZECLmoBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f65.google.com with SMTP id 98e67ed59e1d1-2ee86a1a92dso930363a91.1; Sun, 01 Dec 2024 19:19:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733109595; x=1733714395; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/7PGTzmjpPUY4RIlcJXB5Q1jmNe+Wfb9Ofzi2ziDYRw=; b=mJFSpwT21bwZUZ6/GRfOo7CJ50+78Z8WqYIqo41aJy0bFL8DnYa0jh5p4XNY9Bst0v Yt37Nt3D/ZX8f5Qi2q5LeQ++MRDJo3FT6iY8UuQQWA6kBOhQObqtD+hGxDDONEK9qX1q 4tAr2lXYp7/OHJHJnK3NFrOmbCvjmj8TDR++zPYyOBh/7SQWZaZprBJAaJ3ZUiu3TyKv n6GJ6CQVfFdVvIzwvYdyFICC/RxKfXrtL3TiVnntjRcLunKIWNG6o9A6hvrdnBDG1ZaP BhuQAxPTQiPgVb2OxlGeLIQzmzsw+/PZQGqByp8fJHVCtQXUSDiXM0qatFWZpWGHLDU2 EYVg== X-Forwarded-Encrypted: i=1; AJvYcCUW/vMPwTxV5u4P67qIZfezWUIG58iszqlQGaKA/NI3SFYugrn9IGd7FAFpCHR3FCZR67tcetJDxxFDpWI=@vger.kernel.org, AJvYcCUZjxGn/DkAvx7E/Uj16Tez3OPZoOtYSjIbx06FRTusyCAOpDTIaiY0UriGS2yyqKd7HW2UHjVM5AQ5Y2w2FLY=@vger.kernel.org X-Gm-Message-State: AOJu0YzT2f68IPvAlKSVzRgvjRXhRu3ccN83pok+8Lly1CO9cks1J33m Y3Mf4p7PM5iqB9W9v0IvyOu6DLGW0bPNHGUieRvastDtisFmyb66 X-Gm-Gg: ASbGncvceTINtVdnwHpYDwoH3S3rjIp2slTTsRTLalZ1YLS1aQ4RanGlY3DB+cw0O2F dxVhpHRawwOerDwYlpysbUe/VL9RwyhomuUh1AYre4UaHsjH8iv/Rgs4ynKX/vMwvTHsivcDPGO fLnF7kO03MIuZYhbodDkHdgSkZumkpBN8oIXg0PHNenSyb8CLEXCTWBWCfan0MO20F6/oGTfa+Q UauR6kQb6DD7pSAfb3jnc0fjcQx784iY2tueVWV1jkZLiTeLIZKcPXKBeD6aH5nb1URQzEPVw== X-Google-Smtp-Source: AGHT+IHPuvPyPPD6cvd+D5abHos051/bvNzDVRAVaVZTftg3J9BWL4z22siyBxu7rg8pdYMhYTe9LQ== X-Received: by 2002:a17:90b:3505:b0:2ee:b4bf:2d12 with SMTP id 98e67ed59e1d1-2eeb4bf2eb3mr4701338a91.22.1733109594893; Sun, 01 Dec 2024 19:19:54 -0800 (PST) Received: from kylin-ThinkBook-15-G2-ITL.. ([116.128.244.171]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2eed19aa971sm540723a91.1.2024.12.01.19.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Dec 2024 19:19:54 -0800 (PST) From: xueqin Luo To: nbd@nbd.name, lorenzo@kernel.org, ryder.lee@mediatek.com, shayne.chen@mediatek.com, sean.wang@mediatek.com, kvalo@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com Cc: howard-yh.hsu@mediatek.com, benjamin-jw.lin@mediatek.com, StanleyYP.Wang@mediatek.com, Bo.Jiao@mediatek.com, sujuan.chen@mediatek.com, chui-hao.chiu@mediatek.com, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, make24@iscas.ac.cn, xueqin Luo Subject: [PATCH -next 1/2] wifi: mt76: mt7996: fix overflows seen when writing limit attributes Date: Mon, 2 Dec 2024 11:19:16 +0800 Message-Id: <20241202031917.23741-2-luoxueqin@kylinos.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241202031917.23741-1-luoxueqin@kylinos.cn> References: <20241202031917.23741-1-luoxueqin@kylinos.cn> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DIV_ROUND_CLOSEST() after kstrtoul() results in an overflow if a large number such as 18446744073709551615 is provided by the user. Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations. This commit was inspired by commit: 57ee12b6c514. Fixes: 6879b2e94172 ("wifi: mt76: mt7996: add thermal sensor device support") Signed-off-by: xueqin Luo --- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c index 5e96973226bb..3a175222f8ba 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c @@ -85,7 +85,7 @@ static ssize_t mt7996_thermal_temp_store(struct device *dev, return ret; mutex_lock(&phy->dev->mt76.mutex); - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 40, 130); + val = DIV_ROUND_CLOSEST(clamp_val(val, 40 * 1000, 130 * 1000), 1000); /* add a safety margin ~10 */ if ((i - 1 == MT7996_CRIT_TEMP_IDX && From patchwork Mon Dec 2 03:19:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xueqin Luo X-Patchwork-Id: 13889922 X-Patchwork-Delegate: nbd@nbd.name Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C2EB22EED; Mon, 2 Dec 2024 03:20:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733109610; cv=none; b=oO1wnJ3nmQtZiVkr9HVrMrH8lCvGxLO6+2Vf2uu/4zlczTPFpb6dVM+hjVKik4986kCJ/vNjONLqcjxQna0uvmZho/c5RweFrWaGVAnvDZhqy96pc3YdOEVe5bg6BW96WWgCDjj+mwXZgLGlYoTV71hQhH5B+lBNDrLoXuk+o48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733109610; c=relaxed/simple; bh=AjrFy7cB+gFSVEX8oiD8J1a7UEL1dWiZDBP73ip2qdo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=as6+an93meoGzUKZrZMk9m0MJwR3FxfZuCk86nDPVELAldc6KtQvMShp4qQogLVaH2x+sVP274mv1oxJjg2o5vow6wDQEN8x57PUM1Ak4enNSmE74Ep22BtKx+9m0J1HVfRDJHXVyrmaafbJsJGn7JZwQTXWjYLItQ1Zqustm08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f68.google.com with SMTP id 98e67ed59e1d1-2eb1433958dso2416947a91.2; Sun, 01 Dec 2024 19:20:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733109608; x=1733714408; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cTsDv6X/TDHosGjWCj6G12vDDaZPM/8Azm3atM3kxEg=; b=DYu890YPhTA1CwOS9k4H0C52pvcakOz1eNoDJozzApx1hdd9LFJQFxg5I8zQUwNEj0 FnYOOyrQ3QqD5nhMht8TQe2dhTPNdOFNC86JCBv6H4eH+Ht5yfS2mKT8OpaiR7/MQ9Om x7AussZTY6sM34016Yk/df/jS+9QMLhKW81cUBuHdxZXoMOTah8UAsPVbUscs5hV+F/I teQ1bjNNAzQuqZNZXpET8W94WWJlKyMkRIcgKu4rrMGPpMoToFYiPo31XjxDjecCDo+l Y9qk1ni14pGtYqQKF5Ud6ES1jwbDWxAYeYixW3FQ0F41HXjyECCyTHAgWBvWD4abfMCz GnNQ== X-Forwarded-Encrypted: i=1; AJvYcCUgC4E45jStaZV9KNVGt4SSVDsS0oGYOVpBNu2S919GulTYzldEGI115qN17p0WiExQEmmnps2BEKf3zIz6h5k=@vger.kernel.org, AJvYcCV20imhE/YuO31YT8jxss+9fosF49qLYmJ0EtzP1U/1paYKsNllsOBH0GyVu8kiTXkHIszU2lQvLChqrVs=@vger.kernel.org X-Gm-Message-State: AOJu0YzS0gcUVoD62rQPT7fPN/YazYVE7wfOlqiUgjh0X9rgWdFyZi6L hlCm8v7sMeUWmPbVZRRQcO2JSdRvSnIbrF9Nl5tEW619lTqEfzat X-Gm-Gg: ASbGnct02bklPvCSy6tEBhKSWU2Lm4rMJ7dZqIImUWSE+i7xEhgtuuwZzGzYLfrsno8 B7poegyOsIDGOMlsaOeCfoVry4wU/7OQnzgh5gZAGaC+EmGw8CdlMjTfUkxq/cKAKCniFkVvv1F yCjz+yw9FtVxblln1UzLab8zMXX1eRDJw+N1d1KoUOS02RuBWklHQutdlQ1U30MR49oZK2u8RGs cWJIM6jmOn64JoP/KgvU7pZbUrYeKjrKI4vBhu3ls4NmVU8sZ05qi6PrLXXcwp3it07a1hSvw== X-Google-Smtp-Source: AGHT+IEZfu+l1o1hoQ1rEHsHEhSrUCQ+IgltJe4rj/iDVEpIiZTQOzNjgMefNIoGfMKiTtnF13E2Dg== X-Received: by 2002:a17:90b:180f:b0:2ee:d024:e4f7 with SMTP id 98e67ed59e1d1-2eed024e5d9mr3157086a91.0.1733109607587; Sun, 01 Dec 2024 19:20:07 -0800 (PST) Received: from kylin-ThinkBook-15-G2-ITL.. ([116.128.244.171]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2eed19aa971sm540723a91.1.2024.12.01.19.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Dec 2024 19:20:07 -0800 (PST) From: xueqin Luo To: nbd@nbd.name, lorenzo@kernel.org, ryder.lee@mediatek.com, shayne.chen@mediatek.com, sean.wang@mediatek.com, kvalo@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com Cc: howard-yh.hsu@mediatek.com, benjamin-jw.lin@mediatek.com, StanleyYP.Wang@mediatek.com, Bo.Jiao@mediatek.com, sujuan.chen@mediatek.com, chui-hao.chiu@mediatek.com, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, make24@iscas.ac.cn, xueqin Luo Subject: [PATCH -next 2/2] mt76: mt7915: fix overflows seen when writing limit attributes Date: Mon, 2 Dec 2024 11:19:17 +0800 Message-Id: <20241202031917.23741-3-luoxueqin@kylinos.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241202031917.23741-1-luoxueqin@kylinos.cn> References: <20241202031917.23741-1-luoxueqin@kylinos.cn> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DIV_ROUND_CLOSEST() after kstrtoul() results in an overflow if a large number such as 18446744073709551615 is provided by the user. Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations. This commit was inspired by commit: 57ee12b6c514. Fixes: 02ee68b95d81 ("mt76: mt7915: add control knobs for thermal throttling") Signed-off-by: xueqin Luo --- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c index 6bef96e3d2a3..77d82ccd7307 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c @@ -82,7 +82,7 @@ static ssize_t mt7915_thermal_temp_store(struct device *dev, return ret; mutex_lock(&phy->dev->mt76.mutex); - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 60, 130); + val = DIV_ROUND_CLOSEST(clamp_val(val, 60 * 1000, 130 * 1000), 1000); if ((i - 1 == MT7915_CRIT_TEMP_IDX && val > phy->throttle_temp[MT7915_MAX_TEMP_IDX]) ||