From patchwork Tue Jun 4 16:46:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Panis X-Patchwork-Id: 13685668 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 0DD23C25B78 for ; Tue, 4 Jun 2024 16:47:47 +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:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=fYwejlhI0wMYwD0++rCRpCDh36b+2z2lu94Lt0n2mBQ=; b=4qti3ar0/SJy4A mS6xgGCB0mtx6Z+DISNbsl7lgdl11fWDjOWxzUAamQpYuItaiaGd4kJrBcmME06chUmh/gBDGl2+g tt2fakltRvLOz5N9E1ezFYgTL0RIrlA1ViGuwj4xXx4VN2jFKs/xmNVeOvlN18QK8Nc8VN41gI2CI 3t8k0kHhqwWM7ZUHNL3DRKw+EZ7cgmopDfz3U7wJJNkA4u8dSn0stZQlbItvbs9kCAEh2gdfLPsZ1 StxyZbmoTWVkgduBRayMcE5Q1Dy8Xo6YseUTAcvDNRUngLXZOsmi8t/FwRodScnCqHi7ElBohZc3I 5bFokMa370tW1WhC01Cg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEXJh-00000003Bs4-1NSk; Tue, 04 Jun 2024 16:47:21 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEXJd-00000003Bpw-3zYz for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 16:47:19 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-57a1fe63947so5312609a12.1 for ; Tue, 04 Jun 2024 09:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717519636; x=1718124436; darn=lists.infradead.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=f0ESKMQFpm4YiLCeUzvQbkRJki5AHo+qK/u6Y+vz6Y8=; b=ejWbYz/SslwRh/8KunQrfSpl84/TDNt9vLcy8SXG14rDEtoexJMeDup+oPtmbymtVy sdVMgUEZlhge0TiWVmT4NfG4igfG3YtErrldj2x92Yec11VrBmgf466lbGZWhK7Wjh3a UC5jlevQIimRSezgv85JSGuNCFLkY/eJQhNnn95+mM+MgzkQeb/al0FWm4oE6WpTTx+8 6fWQFsQqQR9LO1uj3kISJhxwMsDYsf5kImF0Og1n4GErUB1N/Nel8WaAbT6TNmwp4Z7M YSnqjycuSomLJyfCOYubRVA/sP/7+nUm8lq65CMdD2S6NZ9BP5Wuowgbga8ctCMg/Aq6 JT4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717519636; x=1718124436; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f0ESKMQFpm4YiLCeUzvQbkRJki5AHo+qK/u6Y+vz6Y8=; b=Nf77MyBgLKacv6VL7/+41SmmWQsZxk0zznEcmcaqEIvgV06qABDiPOFlGHvsdAV5Jk jCW8/BVXNvqyJfUCyFUaAusaGvbKbXVwCYuDuAHDSzAGXLJiruFQLSsC2kM/BrfV2BIv BSoqwknhpuEK+k8U8KUfrgwgRBreSuA3Sv4CSIMRU9hTE80UZNDhGJutwdb/PjEHtuYQ iZ/S9Tng+mUiPinjzFZQjm7I/CuTeGs9vPakNYI1ZFsH73i+D8GlheMd99tVIakGxkhb uyJf2cRPYeCbRL8Af8pYr3B4XLjXEevqtPl8Ccv3aNPhZeQjCCxpXk339x8YA1L1vUde zLWw== X-Forwarded-Encrypted: i=1; AJvYcCWdOXvhojtf4wJjsm4CrPCWC1EjiFUSswKr/CPaHkfxrgR3IypmR/hengyGpc9hN/hGyCarYTKYOU+W/82pHvBDcXbhz4wgroIzrTjWmLSY0aSUOF4= X-Gm-Message-State: AOJu0YyW+OheX3tiZH68KWa8ldrPoGwwcHqsL8ZlDIsa2CxC7twx5+M+ 32zae2GONdKWQHaPHghOxq0Os5hgo2CuN/R1j2n0h9x9zgS+oMnmB8at7F0Wx5k= X-Google-Smtp-Source: AGHT+IFEPd0Vtbd+VXJMfTA36KaKJHIzdgkRVLIFSS5iHePEF4hFxrrXE82EzlfPdPNon9Pquk4nwQ== X-Received: by 2002:a50:a411:0:b0:57a:4b31:5d7c with SMTP id 4fb4d7f45d1cf-57a8b6b7e3dmr105648a12.19.1717519635848; Tue, 04 Jun 2024 09:47:15 -0700 (PDT) Received: from [127.0.1.1] ([84.102.31.231]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a3968bdb7sm7291358a12.46.2024.06.04.09.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 09:47:15 -0700 (PDT) From: Julien Panis Date: Tue, 04 Jun 2024 18:46:58 +0200 Subject: [PATCH v2] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data MIME-Version: 1.0 Message-Id: <20240604-mtk-thermal-calib-check-v2-1-8f258254051d@baylibre.com> X-B4-Tracking: v=1; b=H4sIAAFFX2YC/4WNSw7CMAxEr1J5jVGShi5YcQ/UReK6xOoPJVVEV fXuhF6A5ZvRvNkhcRROcK92iJwlyTIXMJcKKLj5xShdYTDKWNWoGqd1wDVwnNyI5EbxSIFpQO8 Mk7FOU22grN+Re/mc5mdbOEhal7idR1n/0v/OrFHjrWt8r6yy2tLDu63Uka+0TNAex/EFcms9U sEAAAA= To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Matthias Brugger , AngeloGioacchino Del Regno , Nicolas Pitre Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Julien Panis X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1717519634; l=1587; i=jpanis@baylibre.com; s=20230526; h=from:subject:message-id; bh=fEeSbzfW7og883E6MMBCf0UFNWwK83m/m3pTbV2VcBY=; b=cLEAzCE+q/hlZXnwOs3Z0gAUMVPvwZApsPRLT5AzjW3HNJ27YxRfcwRnYZkWI5avHQFon6E/2 GGk0D05B68pCh+oeaWZfQt7ze5LG8FokCaZHE17FRCX+sMr2p3SF0kY X-Developer-Key: i=jpanis@baylibre.com; a=ed25519; pk=8eSM4/xkiHWz2M1Cw1U3m2/YfPbsUdEJPCWY3Mh9ekQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240604_094718_042808_E463D6D0 X-CRM114-Status: GOOD ( 13.40 ) 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 This patch prevents from registering thermal entries and letting the driver misbehave if efuse data is invalid. A device is not properly calibrated if the golden temperature is zero. Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver") Signed-off-by: Julien Panis Reviewed-by: Nicolas Pitre Reviewed-by: AngeloGioacchino Del Regno --- Guard against invalid calibration data, following this discussion: https://lore.kernel.org/all/ad047631-16b8-42ce-8a8d-1429e6af4517@collabora.com/ --- Changes in v2: - Add Fixes tag. - Link to v1: https://lore.kernel.org/r/20240603-mtk-thermal-calib-check-v1-1-5d6bf040414c@baylibre.com --- drivers/thermal/mediatek/lvts_thermal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- base-commit: 632483ea8004edfadd035de36e1ab2c7c4f53158 change-id: 20240603-mtk-thermal-calib-check-ba2ec24a1c32 Best regards, diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index 0bb3a495b56e..185d5a32711f 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -769,7 +769,11 @@ static int lvts_golden_temp_init(struct device *dev, u8 *calib, */ gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff; - if (gt && gt < LVTS_GOLDEN_TEMP_MAX) + /* A zero value for gt means that device has invalid efuse data */ + if (!gt) + return -ENODATA; + + if (gt < LVTS_GOLDEN_TEMP_MAX) golden_temp = gt; golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset;