From patchwork Mon Jun 3 12:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Panis X-Patchwork-Id: 13683723 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 78398C25B75 for ; Mon, 3 Jun 2024 12:07:17 +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=Bl3bhb8/rFmLO+e6dfJnrpvky7w1idDFPCtiD9LMzl0=; b=0KQKGrrgc3PZ3L A7hNeXnAu3JG1E3oadbBjwkQcz6Xhm59b709Guhy4JKiUfD5KJWi0k0Ai/xqjmp2EM3D3TiT1YX6A MIw6rVHatHOO3fx+Sr2+9JBQQn58lnK7CobfLHDAXzimLD6R9imKXst75NVw1Hzvq8AtvpqJUe3kB l+laH0U272Eax4Ld97uKnDL0WKbLomAPD4pKszk0bfl7/K2V/+XaQf5X0i7DV7Lp7vcIGnSc62brs n4LtNwK051LaoXgaGc3xxJGkmdFa19C8DArcPCnKpEISnHREOrTdTBsPBE8sciZTng1ZHCbRZxM5A Q0T9NsmWw+m/4dZSRvEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE6St-0000000GcZy-2W6Y; Mon, 03 Jun 2024 12:07:03 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE6Sp-0000000GcYO-28t2 for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 12:07:02 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4212f0444efso22493265e9.1 for ; Mon, 03 Jun 2024 05:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717416415; x=1718021215; 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=vzs/x1WCN5t2imfhC6zu+ZDUGVxVyZ0jYD0hK5bZuVY=; b=Qn37HwVfFB6GWTvAiLfJGqLJOBM3K4pWyvZxLAl4rWZiq6zOlVPY5dQA5KsP5uubqm GRhwzGyMb7xUDyrN61yf3x89qSyrSzo2vC6CqSmUWKnqSInuiTqtOCZrnXgpqGBa9/DQ 8uoqOEFbnizAWNzS6tIzBfGlXHglP19huszxSYExyEzozazAqwClko+MvHVAEY7H5CDq nn7h+KoiGB5qlL4S9VQX0a+OmQo+/3qkHGKpClfaW6P8jAQjhVhcUJIc2zMd2UJruZ5m eQkrmELDV9TH7H15xWTTHMaH9PmazcLW3Oop13EDf+iXrhypq0eu2GaHZAb3u/pIfSy3 oL0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717416415; x=1718021215; 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=vzs/x1WCN5t2imfhC6zu+ZDUGVxVyZ0jYD0hK5bZuVY=; b=M4gnqr5zlsFSWVg7ZZ2Y2BXygjYJPHDEqUYZFhVOHzndf3ZuR3b2UfD4yZGZSftUf8 563d2kk+HECYeM7t+a7n2tvCwKQxPQ4WnDTasuLLPas3rQdfQoAEv+X//XelMxDMQxwX 4h6PcFOY6lCUToed+mTYiPDT1xCkEqPUpkr8aSKhcBGp6+fE8/M1sbk7SZYfFNMTbjqv 5FKoaVYLqmDTqxsJwYGTNgQOil1h9VLI0R511fBoJemHGE/Y8z7g1XILcYkV1ExYp3RX jyDYcOCKMxYeavebAY1Gdj15iV/dXyrjItNsgQMJMuzwkEdOxEsmb1NKIF3zDZvv+Zvd eatg== X-Forwarded-Encrypted: i=1; AJvYcCWOl4OB8DHVy5ZNzrTIz6c+vSMBvcL4k4edZaWv4S69dOzn+i0BvGE8D8z2gijpLs6JkVcEQVM/H0eYN+R1un9FT8u3dpSvf1jm074H/RbbwSZBEsM= X-Gm-Message-State: AOJu0Yy+lKeQWs6ibMx1nHWOXI+x5Vscg3F+BNNBfOdJHNGQ9iJZKvRc vEmjbZJ1K9nn5SkwLtrpSUxEp7vPxNhw+fuWT1n4m+WeZPPGkxG1Edt/FkjqK70= X-Google-Smtp-Source: AGHT+IHUt9RC5PnZgMhb+jbLRK9Usa/RFjFRgNU7nFyyp0EjKf8YEFj7904Gl2PsM4H49yscOAhb2A== X-Received: by 2002:a05:600c:1e27:b0:41b:de8d:dcd7 with SMTP id 5b1f17b1804b1-4212e05f21dmr64794825e9.20.1717416414555; Mon, 03 Jun 2024 05:06:54 -0700 (PDT) Received: from [127.0.1.1] ([84.102.31.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4212b8a758csm114805625e9.36.2024.06.03.05.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 05:06:54 -0700 (PDT) From: Julien Panis Date: Mon, 03 Jun 2024 14:06:49 +0200 Subject: [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data MIME-Version: 1.0 Message-Id: <20240603-mtk-thermal-calib-check-v1-1-5d6bf040414c@baylibre.com> X-B4-Tracking: v=1; b=H4sIANixXWYC/x3MPQqAMAxA4atIZgM1ioNXEYcYow3+0ooI4t0tj t/w3gNRg2mEJnsg6GXR9i2hyDMQz9ukaEMykKPK1a7E9Zzx9BpWXlB4sR7Fq8zYM6lQxYWUBKk +go52/+e2e98PFKMvwGkAAAA= 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=1717416412; l=1350; i=jpanis@baylibre.com; s=20230526; h=from:subject:message-id; bh=K0CDQC1akX83WqstZzLmNolRnOazVmg2PvHJe4bg5Q0=; b=sKRmkGPrCbvTekNrVxBLMIUjflnb9FNPMqlYmPYKF9gHcSfU2hOCEY6bHSIh7DWFYzVrvifv+ y++zucbPtypDRYxmAMdAcYHk+bJiO+sNe3XEydI64hVHnRlwdB73rxL 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-20240603_050659_691887_493AB761 X-CRM114-Status: GOOD ( 12.75 ) 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. Signed-off-by: Julien Panis Reviewed-by: Nicolas Pitre --- Guard against invalid calibration data, following this discussion: https://lore.kernel.org/all/ad047631-16b8-42ce-8a8d-1429e6af4517@collabora.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;