From patchwork Tue Mar 7 13:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 13163600 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0DDE3C678D4 for ; Tue, 7 Mar 2023 13:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Dzle9gfWcHN40m17EjC7sfbM63tPqEqYPAoBIM7gMx8=; b=mUzHyU2+PVfVxW 6pqm4XApCUzSCd7v0pWholw1lBYeELd2hEvDA3kpEzyYOHNlEMm6mQvgGnudFVLwe1lNC5602HUP9 aJIwJSUw95r/UzqEdNdUu/3TGwG99Tar0TNBBHmF9p5ToRfKrQYtz+XU6y8xWsifuMb8vJqay0MpR Lecq4NzaRfh8AkIOrRJxkP1y3BZcYNbLKxh6PfMgg/Nv0sGcyAyJ9hxqKsWv1LWpWFGdIze/UW0rP 75dy3+hbFg2CMiWaiUZdpBVuMquG8pGiiZSZ2ucb5221Z+HN64IdMk9ydqYkuuBj/hPltiS3By0il 57EeXPW3r1ukB6rSWd7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZXmX-000YRz-4s; Tue, 07 Mar 2023 13:55:11 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZXac-000TQG-JR for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 13:42:52 +0000 Received: by mail-wr1-x42c.google.com with SMTP id l1so12117736wry.12 for ; Tue, 07 Mar 2023 05:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1678196568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Eeel5XHVDoFzIY2YG1FRNg5liLwMdDxd6X70lesaeNg=; b=cbqb/e/w8w236fE3rmjvQsm/3PyhLPMdyuWqyoTBlqyuTuh4Zx/mzq9dD/hjQM321F EPB63dMqDynEzEDCff8rJuhWAX0PUbR47loqbnjH60nmVA00l41/8wBdy7xRukr/QcUB ++pbWDmgErb4+w499XFEq4DfaPlLlTf3SdD8SrXqLCdEL2MyhQvoRBTKg20+piBh5+m/ CCCuJRSWnewbDQIs/r6yxYgEhDO4p3noRsmSDMMaAnHkeTvDz7rQxGYCDnkyJAU1AC7U 1dy7QQb3V8jKCHqPH19PBYbF6nyFthwQQZ6D+8uFXby+DfyGtvOZHdG91NHBDkmmwQ5u OPSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678196568; 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=Eeel5XHVDoFzIY2YG1FRNg5liLwMdDxd6X70lesaeNg=; b=fOb4dPtXDnGTXpwnBw9gLFEM6bARg2WUVcltkEj2YUgfFKJCvUXleZ7VtL+d5Er8CC abYftPRwcMi1cBSKriw+hmGfN+gIGHipwt+AHXH7ojFWz/8Aa2g3LYgfXSxw6Gi6t6H1 Df7oqVOSbKJ2NJJxE2qWZBoGR5ArhwvXILAo/yVXQDrlrocwdgKCCm9okHW6orDCNAZw c53+5bpKfo6XIQxPORnucNbZE9yWyhVxuA9+5yqKthZV7cQvSIyVmMIjtjKXE/SSkNYx QqZCpcrnjOnbWcSNiLGnOx3P3KYy1SoK4rWGDe/Io0iDX9GKA+OOQxJNDmdqg2TulS+U 6NIQ== X-Gm-Message-State: AO0yUKVRPnnElylXf5q+9wWcuJTXedta5GaGI9ApIgCzzkJMgs3k5cbE DfIkK18lRpTV0bxQpuqI/ZdOWw== X-Google-Smtp-Source: AK7set+aspRSIaTh4/XbS+bw8KYAx2Ifi6PVWrobx0AWeOOli8vUV5Ail29oq9+yZ42Y9gSmbdGEzw== X-Received: by 2002:adf:ea90:0:b0:2c9:d90c:56c3 with SMTP id s16-20020adfea90000000b002c9d90c56c3mr8924250wrm.53.1678196568111; Tue, 07 Mar 2023 05:42:48 -0800 (PST) Received: from localhost.localdomain (laubervilliers-657-1-248-155.w90-24.abo.wanadoo.fr. [90.24.137.155]) by smtp.gmail.com with ESMTPSA id f2-20020a5d4dc2000000b002be5bdbe40csm12495589wru.27.2023.03.07.05.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 05:42:47 -0800 (PST) From: bchihi@baylibre.com To: daniel.lezcano@linaro.org, angelogioacchino.delregno@collabora.com, rafael@kernel.org, amitk@kernel.org, rui.zhang@intel.com, matthias.bgg@gmail.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, rdunlap@infradead.org, ye.xingchen@zte.com.cn, p.zabel@pengutronix.de Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, khilman@baylibre.com, james.lo@mediatek.com, rex-bc.chen@mediatek.com Subject: [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() Date: Tue, 7 Mar 2023 14:42:45 +0100 Message-Id: <20230307134245.83599-1-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126161048.94089-1-bchihi@baylibre.com> References: <20230126161048.94089-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_054250_658989_E9582AF7 X-CRM114-Status: GOOD ( 15.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Balsam CHIHI Replace memcpy 2 bytes by sizeof(int) bytes of LVTS calibration data. Reported-by: Dan Carpenter Signed-off-by: Balsam CHIHI --- Rebased on top of thermal/linux-next base-commit: 6828e402d06f7c574430b61c05db784cd847b19f Original email : Hello Balsam CHIHI, The patch f5f633b18234: "thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver" from Feb 9, 2023, leads to the following Smatch static checker warning: drivers/thermal/mediatek/lvts_thermal.c:562 lvts_calibration_init() warn: not copying enough bytes for '&lvts_ctrl->calibration[i]' (4 vs 2 bytes) drivers/thermal/mediatek/lvts_thermal.c 555 static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl, 556 const struct lvts_ctrl_data *lvts_ctrl_data, 557 u8 *efuse_calibration) 558 { 559 int i; 560 561 for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++) --> 562 memcpy(&lvts_ctrl->calibration[i], 563 efuse_calibration + lvts_ctrl_data->cal_offset[i], 2); ^ This is copying an array of known ints to a u32 array. It should copy sizeof(int) instead of 2. It only works because the data you're on little endian and the data is small. 564 565 return 0; 566 } regards, dan carpenter --- --- drivers/thermal/mediatek/lvts_thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 6828e402d06f7c574430b61c05db784cd847b19f prerequisite-patch-id: 73be949bd16979769e5b94905b244dcee4a8f687 prerequisite-patch-id: d23d83a946e5b876ef01a717fd51b07df1fa08dd prerequisite-patch-id: d67f2455eef1c4a9ecc460dbf3c2e3ad47d213ec prerequisite-patch-id: 9076e9b3bd3cc411b7b80344211364db5f0cca17 prerequisite-patch-id: e220d6ae26786f524c249588433f02e5f5f906ad prerequisite-patch-id: b407d2998e57678952128b3a4bac92a379132b09 prerequisite-patch-id: fbb9212ce8c3530da17d213f56fa334ce4fa1b2b prerequisite-patch-id: 5db9eed2659028cf4419f2de3d093af7df6c2dad prerequisite-patch-id: a83c00c628605d1c8fbe1d97074f9f28efb1bcfc prerequisite-patch-id: 56a245620a4f8238cf1ba3844dc348de3db33845 prerequisite-patch-id: 7df24b0bf11129ddd3356eacf192cc3fdb2bcded prerequisite-patch-id: 3213ca70cb5b26d54a7137ff40ca8cd2a795c414 prerequisite-patch-id: 6c2202e85215d1c7e8ab16a6b85922e994c68d9b diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index ddfdcbcf6d86..b505c6b49031 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -575,7 +575,7 @@ static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++) memcpy(&lvts_ctrl->calibration[i], - efuse_calibration + lvts_ctrl_data->cal_offset[i], 2); + efuse_calibration + lvts_ctrl_data->cal_offset[i], sizeof(int)); return 0; }