All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Sasha Levin" <sashal@kernel.org>,
	jdelvare@suse.com, linux-hwmon@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 27/29] hwmon: (sht15) Fix wrong assumptions in device remove callback
Date: Sun,  7 Aug 2022 21:37:37 -0400	[thread overview]
Message-ID: <20220808013741.316026-27-sashal@kernel.org> (raw)
In-Reply-To: <20220808013741.316026-1-sashal@kernel.org>

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

[ Upstream commit 7d4edccc9bbfe1dcdff641343f7b0c6763fbe774 ]

Taking a lock at the beginning of .remove() doesn't prevent new readers.
With the existing approach it can happen, that a read occurs just when
the lock was taken blocking the reader until the lock is released at the
end of the remove callback which then accessed *data that is already
freed then.

To actually fix this problem the hwmon core needs some adaption. Until
this is implemented take the optimistic approach of assuming that all
readers are gone after hwmon_device_unregister() and
sysfs_remove_group() as most other drivers do. (And once the core
implements that, taking the lock would deadlock.)

So drop the lock, move the reset to after device unregistration to keep
the device in a workable state until it's deregistered. Also add a error
message in case the reset fails and return 0 anyhow. (Returning an error
code, doesn't stop the platform device unregistration and only results
in a little helpful error message before the devm cleanup handlers are
called.)

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20220725194344.150098-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/hwmon/sht15.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index 7f4a63959730..ae4d14257a11 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -1020,25 +1020,20 @@ static int sht15_probe(struct platform_device *pdev)
 static int sht15_remove(struct platform_device *pdev)
 {
 	struct sht15_data *data = platform_get_drvdata(pdev);
+	int ret;
 
-	/*
-	 * Make sure any reads from the device are done and
-	 * prevent new ones beginning
-	 */
-	mutex_lock(&data->read_lock);
-	if (sht15_soft_reset(data)) {
-		mutex_unlock(&data->read_lock);
-		return -EFAULT;
-	}
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group);
+
+	ret = sht15_soft_reset(data);
+	if (ret)
+		dev_err(&pdev->dev, "Failed to reset device (%pe)\n", ERR_PTR(ret));
+
 	if (!IS_ERR(data->reg)) {
 		regulator_unregister_notifier(data->reg, &data->nb);
 		regulator_disable(data->reg);
 	}
 
-	mutex_unlock(&data->read_lock);
-
 	return 0;
 }
 
-- 
2.35.1


  parent reply	other threads:[~2022-08-08  1:54 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08  1:37 [PATCH AUTOSEL 5.10 01/29] x86: Handle idle=nomwait cmdline properly for x86_idle Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 02/29] arm64: Do not forget syscall when starting a new thread Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 03/29] arm64: fix oops in concurrently setting insn_emulation sysctls Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 04/29] ext2: Add more validity checks for inode counts Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 05/29] genirq: Don't return error on missing optional irq_request_resources() Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 06/29] irqchip/mips-gic: Only register IPI domain when SMP is enabled Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 07/29] genirq: GENERIC_IRQ_IPI depends on SMP Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 08/29] irqchip/mips-gic: Check the return value of ioremap() in gic_of_init() Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 09/29] wait: Fix __wait_event_hrtimeout for RT/DL tasks Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 10/29] ARM: dts: imx6ul: add missing properties for sram Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 11/29] ARM: dts: imx6ul: change operating-points to uint32-matrix Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 12/29] ARM: dts: imx6ul: fix keypad compatible Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 13/29] ARM: dts: imx6ul: fix csi node compatible Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 14/29] ARM: dts: imx6ul: fix lcdif " Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 15/29] ARM: dts: imx6ul: fix qspi " Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 16/29] ARM: dts: BCM5301X: Add DT for Meraki MR26 Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 17/29] spi: synquacer: Add missing clk_disable_unprepare() Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 18/29] ARM: OMAP2+: display: Fix refcount leak bug Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 19/29] ACPI: EC: Remove duplicate ThinkPad X1 Carbon 6th entry from DMI quirks Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 20/29] ACPI: EC: Drop the EC_FLAGS_IGNORE_DSDT_GPE quirk Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 21/29] ACPI: PM: save NVS memory for Lenovo G40-45 Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 22/29] ACPI: LPSS: Fix missing check in register_device_clock() Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 23/29] arm64: dts: qcom: ipq8074: fix NAND node name Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 24/29] arm64: dts: allwinner: a64: orangepi-win: Fix LED " Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 25/29] ARM: shmobile: rcar-gen2: Increase refcount for new reference Sasha Levin
2022-08-08  1:37   ` Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 26/29] firmware: tegra: Fix error check return value of debugfs_create_file() Sasha Levin
2022-08-08  1:37 ` Sasha Levin [this message]
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 28/29] PM: hibernate: defer device probing when resuming from hibernation Sasha Levin
2022-08-08  1:37 ` [PATCH AUTOSEL 5.10 29/29] selinux: Add boundary check in put_entry() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220808013741.316026-27-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=stable@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.