From patchwork Mon Feb 13 18:22:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 56429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2502340wrn; Mon, 13 Feb 2023 10:29:36 -0800 (PST) X-Google-Smtp-Source: AK7set9IuXbCJp+wYTqwWj6wyjQKFJz5RIkAMoNGI2VU453AUetlecvl9sAtWGeZDYweb0mPotgz X-Received: by 2002:a50:9feb:0:b0:4ac:b3af:1e1 with SMTP id c98-20020a509feb000000b004acb3af01e1mr10641453edf.13.1676312976159; Mon, 13 Feb 2023 10:29:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676312976; cv=none; d=google.com; s=arc-20160816; b=sxHC0iQNWprVp5E1IK4M++hEo9HQRsi6ofWCobeXB7yEvbA8rO/XalFQhwH+UFU0Zt 5U024m+mqg3Qcc7t4y4EHBmeqHKAVAkp0zmbf5pdIL1szapu2JH/LS4V1OqsBXZIMZQA 2gDICpDe1Us4F0oPO7TpJTIXDLGiJmK4Jok8lPs5TAatTq0Kx2InCKDFuz5ZW0iZjmNm S5qEafEiosVcza8w1TDXu1kr8qe2J1p0IOJpwhO0AgR20T97Pwem/VgbQZnuh7FnUF9n OOGHvwZKSUgKPv+VRxjEY0xhogz3yUAfEZPiJPt3wNRdUqGeryY53FXzV67Q0IV5zxSu FwFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=lIZC1op64Y0HWKr0y37x78CYbOYM5ymF7Em2b6gocqQ=; b=JrSgBXgtysa3QYRmQLIeh5lJOTBJq2+9OJD2r4i6qIZwPVJmrQCLCsDoFm9TxxDaBt tkXWIWqausmF1CjV6cLDvpkYD9Ct3Tg/3hzi8SH1Hfh4YcOrAqVLZyq7H8NE4sIgejD+ mouEenm60Jyw4rtheuJlXhq3vopbLX1SIIGY8G4tWr2rGqaQOHHzU9IYOlCa2ClkBgU4 +VxllpnEJlt2tj86GQR8B+kfbLgDBQrimpv7ukzVhzpkqAvb21oRcOEMMUS3XTPcnzsO poJVo8L3/kDoexDT5PmH7n1xysQYN1XFlpWfPo/dsrGBAR9kURguATVNJnmMULy+WZEN 13Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=JcUyi3VK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a50ed08000000b00497431159d4si14186119eds.532.2023.02.13.10.29.12; Mon, 13 Feb 2023 10:29:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=JcUyi3VK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbjBMSX2 (ORCPT + 99 others); Mon, 13 Feb 2023 13:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbjBMSXP (ORCPT ); Mon, 13 Feb 2023 13:23:15 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4013E5596; Mon, 13 Feb 2023 10:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1676312549; bh=k12c6zpHprezemc3Q5ubUFsaXlGc2har9SHXA5+paEI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=JcUyi3VKtz/3ypoVSInsLrLw4V2oyxcWBNyuVdbr5JX49Dmkk3lC8jgADvlLzgh7k pidNUdTcrpjU07JAN0s0dCZP3rtniIAeYrBP8AAp9O5NuFhjiA8uoDpPmquwg5AwS7 p5rgTvCA07GqU+cC9f266jNSyvgc5IcmD1OvZirv40fQHZn38wISrokM4/kYkuB8vN 5CwhOW/WbStPKVQMramegVAhyyPkf9HwNj+234k3R/Lz2UbHlY9xVi5lmL4HKa5cNu A02Eox6RR5bb9pJGM1o+cxE7SCSScQcloepr6Wpu+Z+JVFvFLQBty3YMxFYidqJVWJ KVYVWVVQcnZfQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M3DJl-1pQnSS0Pdt-003bcv; Mon, 13 Feb 2023 19:22:29 +0100 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] platform/x86: dell-ddv: Fix cache invalidation on resume Date: Mon, 13 Feb 2023 19:22:14 +0100 Message-Id: <20230213182215.53703-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Provags-ID: V03:K1:vvmoBXbeMMdQXvxmbFvA+IKtYLvXu8GmIvKNzcZTX2BmVRXgpWV XZRCQoZr7zdQDqh+2ogr+ggJxaqROGv9LyB4npHtP74HBvkf37XUnugGjnpaq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qrGkXF1Mg++A5WjOsbPczXMkaIzE0h0YMGJ 4Hzf6CQq4TJpeOeUIRnkHkNUIrs= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757741555404642254?= X-GMAIL-MSGID: =?utf-8?q?1757741555404642254?= If one or both sensor buffers could not be initialized, either due to missing hardware support or due to some error during probing, the resume handler will encounter undefined behaviour when attempting to lock buffers then protected by an uninitialized or destroyed mutex. Fix this by introducing a "active" flag which is set during probe, and only invalidate buffers which where flaged as "active". Tested on a Dell Inspiron 3505. Fixes: 3b7eeff93d29 ("platform/x86: dell-ddv: Add hwmon support") Signed-off-by: Armin Wolf --- drivers/platform/x86/dell/dell-wmi-ddv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) -- 2.30.2 diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c index d547c9d09725..58f996b3b374 100644 --- a/drivers/platform/x86/dell/dell-wmi-ddv.c +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c @@ -96,6 +96,7 @@ struct combined_chip_info { }; struct dell_wmi_ddv_sensors { + bool active; struct mutex lock; /* protect caching */ unsigned long timestamp; union acpi_object *obj; @@ -530,6 +531,7 @@ static void dell_wmi_ddv_hwmon_cache_destroy(void *data) { struct dell_wmi_ddv_sensors *sensors = data; + sensors->active = false; mutex_destroy(&sensors->lock); kfree(sensors->obj); } @@ -549,6 +551,7 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_init(struct wmi_device *w return ERR_PTR(ret); mutex_init(&sensors->lock); + sensors->active = true; ret = devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_hwmon_cache_destroy, sensors); if (ret < 0) @@ -852,9 +855,12 @@ static int dell_wmi_ddv_resume(struct device *dev) { struct dell_wmi_ddv_data *data = dev_get_drvdata(dev); - /* Force re-reading of all sensors */ - dell_wmi_ddv_hwmon_cache_invalidate(&data->fans); - dell_wmi_ddv_hwmon_cache_invalidate(&data->temps); + /* Force re-reading of all active sensors */ + if (data->fans.active) + dell_wmi_ddv_hwmon_cache_invalidate(&data->fans); + + if (data->temps.active) + dell_wmi_ddv_hwmon_cache_invalidate(&data->temps); return 0; }