Message ID | 20230218115318.20662-1-W_Armin@gmx.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp337237wrn; Sat, 18 Feb 2023 03:55:22 -0800 (PST) X-Google-Smtp-Source: AK7set8t5e3m1bHnkkclu1DSSd8hn+j+iOcLxnBn0hh1qAAJ14rhl0a6hnZpByyINUEoGaPvSs0y X-Received: by 2002:a17:906:c289:b0:8b8:c04f:c5f9 with SMTP id r9-20020a170906c28900b008b8c04fc5f9mr3167246ejz.73.1676721321878; Sat, 18 Feb 2023 03:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676721321; cv=none; d=google.com; s=arc-20160816; b=sFYnV53IfW56CQiVoDw0dpaSAM8gmM6SkBJSP2JreJ214qmM41HkyInQvVj2wEagIQ t/d3ryc33MLpATPTw9oPrhUSM89MnIlHsB6TW+87t3xyEXXQjadDau/jey6L4bpqZPEQ cUiULoylMmpYagujsYOCNg2uZZ641Ss60QM+2ba9arREgQO2hEcgdKRhvi2gdEcmSAUw fJiJMnJQ6jCzl1m7cjcEtSKVQTVLUlWYyrzZq/Gk302S+kc2Xv+eMtWOS3E0UDQOX7ZE K9ULWbxs3I1CrzvtaLj6YpPD1u1XtKAEqFdQaMnnpcCGKxQdvxp0MVlE4KuYRf1TeHmP UJAg== 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=MP4Hu8K87HMgwMpzSMwv7cWWcRqG3JNx1+WNdO/yUjU=; b=qmnd/W+rlpoIW1KXzErYR08ZUhDTLhXjkfMIqTxsRTIO/RtsXtlb7fM97RalkFZ2Wt 5pd7zN2NDtr2KiM3/+gd1iQdamtNDzAeyPoG9Meb3k+WfolynoUXlbCuNRHzwlqI+gCR gvEZtHKTZm/yIl7sX+Q/fNmMFMgDyVuHXzxfrn+2IKp9bG8iih1FL4eaPhCKGJFMGn0Y pw4EKWjDtOtc4oB9hIW8n3JHZWlBupuACDYcnIjsFxDeSISTcu6UoYF93nr0A9mhtRsY cgr4DO8HIEfH9cvwmFHmjBx33Jcnfx54/X0qrBLG0ZFEiH17J1+kcwwLKYele+aWB/Dr DfSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=AjnaHu7B; 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 n23-20020a17090673d700b008b133b9a517si10162292ejl.113.2023.02.18.03.54.58; Sat, 18 Feb 2023 03:55:21 -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=AjnaHu7B; 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 S229496AbjBRLxu (ORCPT <rfc822;assdfgzxcv4@gmail.com> + 99 others); Sat, 18 Feb 2023 06:53:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjBRLxt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 18 Feb 2023 06:53:49 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0147713D5F; Sat, 18 Feb 2023 03:53:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1676721204; i=w_armin@gmx.de; bh=/fmzoCaMhnWReJYZfoH3jC5r2/1L4ZtHhXop0SMK+UE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=AjnaHu7B/QYyUWn++aMX2z2PDtT2WQv0dRmm4KrGTRWpbYkdk0QCyX10FupKRt6mL J269UD2U5ug5T7Ma3WajNoCsQdTMaRokHFO/s1J/9HBkeJZ7eSpt7dw+4wnsYnq1Dq Inzzk9OreeokGPdY6nL9hjQ5Owmp9eqQPBzyrFKY11VkpycF4Qc00gpoECi2UdFACV P0c0Bevx1EatxFtTbG4RIkJxKC8KWg5B51O2tGr5KWpmGGx6z9W/CMY6TY5i6+mG2a G9yKLu/TAvGEp2bnSfd7ao0v7LEBNtxu++Y1ApYhxxiutzyhEq8lwdofzYJ3DjMNU7 eWiXcVGLO4CzQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MTRMi-1p6H0x3WjU-00TiXJ; Sat, 18 Feb 2023 12:53:23 +0100 From: Armin Wolf <W_Armin@gmx.de> 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 v2 1/2] platform/x86: dell-ddv: Fix cache invalidation on resume Date: Sat, 18 Feb 2023 12:53:17 +0100 Message-Id: <20230218115318.20662-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:77WJU57lj8Qu0dhg8UbEVrImGjypha5gHmE/E8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2gF/0oxFbu9B/bL2E2+T7nTeJnO3+bl5vakMXgbKSuwmywN0TVCIfge zRsA654Rl3YTCOQ2ne2QJKbvvCLdXw3S+0hKOdSH+YrILxg36GwLRtgWHVHLbzZhL4WVAfnh2 07p/+FfC3A5okUWWcXgiVgp1n1w= 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758169736592171736?= X-GMAIL-MSGID: =?utf-8?q?1758169736592171736?= |
Series |
[v2,1/2] platform/x86: dell-ddv: Fix cache invalidation on resume
|
|
Commit Message
Armin Wolf
Feb. 18, 2023, 11:53 a.m. UTC
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 <W_Armin@gmx.de>
---
Changes in v2:
- move checking of the "active" flag inside
dell_wmi_ddv_hwmon_cache_invalidate()
---
drivers/platform/x86/dell/dell-wmi-ddv.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--
2.30.2
Comments
Am 18.02.23 um 12:53 schrieb Armin Wolf: > 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. Hello, what is the status of this series? Both patches are tested on real hardware and work flawlessly. Armin Wolf > Fixes: 3b7eeff93d29 ("platform/x86: dell-ddv: Add hwmon support") > Signed-off-by: Armin Wolf <W_Armin@gmx.de> > --- > Changes in v2: > - move checking of the "active" flag inside > dell_wmi_ddv_hwmon_cache_invalidate() > --- > drivers/platform/x86/dell/dell-wmi-ddv.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c > index d547c9d09725..eff4e9649faf 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; > @@ -520,6 +521,9 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_create(struct device *dev > > static void dell_wmi_ddv_hwmon_cache_invalidate(struct dell_wmi_ddv_sensors *sensors) > { > + if (!sensors->active) > + return; > + > mutex_lock(&sensors->lock); > kfree(sensors->obj); > sensors->obj = NULL; > @@ -530,6 +534,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 +554,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,7 +858,7 @@ 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 */ > + /* Force re-reading of all active sensors */ > dell_wmi_ddv_hwmon_cache_invalidate(&data->fans); > dell_wmi_ddv_hwmon_cache_invalidate(&data->temps); > > -- > 2.30.2 >
Hi, On 2/18/23 12:53, Armin Wolf wrote: > 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 <W_Armin@gmx.de> > --- > Changes in v2: > - move checking of the "active" flag inside > dell_wmi_ddv_hwmon_cache_invalidate() Thanks, I've applied this patch to my review-hans branch: https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans I'll rebase that branch once 6.3-rc1 is out and then push the rebased patch to the fixes branch and include it in my next 6.3 fixes pull-req to Linus. Regards, Hans > --- > drivers/platform/x86/dell/dell-wmi-ddv.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c > index d547c9d09725..eff4e9649faf 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; > @@ -520,6 +521,9 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_create(struct device *dev > > static void dell_wmi_ddv_hwmon_cache_invalidate(struct dell_wmi_ddv_sensors *sensors) > { > + if (!sensors->active) > + return; > + > mutex_lock(&sensors->lock); > kfree(sensors->obj); > sensors->obj = NULL; > @@ -530,6 +534,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 +554,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,7 +858,7 @@ 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 */ > + /* Force re-reading of all active sensors */ > dell_wmi_ddv_hwmon_cache_invalidate(&data->fans); > dell_wmi_ddv_hwmon_cache_invalidate(&data->temps); > > -- > 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..eff4e9649faf 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; @@ -520,6 +521,9 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_create(struct device *dev static void dell_wmi_ddv_hwmon_cache_invalidate(struct dell_wmi_ddv_sensors *sensors) { + if (!sensors->active) + return; + mutex_lock(&sensors->lock); kfree(sensors->obj); sensors->obj = NULL; @@ -530,6 +534,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 +554,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,7 +858,7 @@ 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 */ + /* Force re-reading of all active sensors */ dell_wmi_ddv_hwmon_cache_invalidate(&data->fans); dell_wmi_ddv_hwmon_cache_invalidate(&data->temps);