Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4252193rwb; Sun, 7 Aug 2022 19:23:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR5gjwJleTSxCpXxz/N/sDNy8JPMvLwQhC6xLOD+8elmerF5jvcIyJHgewvGpRlYJZBA9Zjw X-Received: by 2002:a65:6944:0:b0:41b:4483:35cc with SMTP id w4-20020a656944000000b0041b448335ccmr14400572pgq.296.1659925400212; Sun, 07 Aug 2022 19:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659925400; cv=none; d=google.com; s=arc-20160816; b=Z8Bwpj8WamvJtbvxfz5vWWVbyBK3mTNpINiIkvADqVCkLaogW4pH2jXC/eO/vod0on v8Y8FwHMjPe5G/FDRlYYFZ/YWWXQWgFk/m+0W+Xjr2D1e6rzfUB7dolIV6wtGptXZsDW Ngh4Ws5B/ZKgbZmBgrtTNMp1zly/p0sbh1/GYCQr762oqlqvdADoIvbpDsiGCZ9bEJQh NJJlbuK8oizp9+y9PCk9/RjRXZKvB1z7A/gtrfGavWQcNZDu1BudelM97yBKaZudmGpf LJCeX2e6dsRvcw0s3cHRPbjQclxtCPwRw65xFfJfyOntcM3gBGeZ/df8rvGHOHJn+WfJ Id3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QbBWWilInTjrtqSgOS9AVQewBHKlNZeKe7SdyBsKsLI=; b=jUwXYkHRE8LuvKPbZYoHhL7jc43xwxDa3Ugm+SYStY09pUyC/wlD3SYyPiX/0w4phj dhY2nUoGdH5EPrYc0i//bIHoeQW46+3aUgC9ViEWZlkdewXDVij98VO2CbNica8v6kr4 o8/jpxJ2vqxXfKsGHNwiHtw5Fkpn41d4RmOumd1vNEKyEdfka1v6Jxjy3hvlKW/vfzlI 4knqMK2V3LjonqZ3FjRzPdie80i95sbzkLLb0syqQcfqUpyYaU3stToVxYCRBQGEPVLi t2dNGlonL+GcsvfnwS2lpqhOpjj2JgJwBVBjzPpHGvSSAUrZFcdfA7/UQWI75Ijafy4b 8BLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ej0Ok/or"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u68-20020a637947000000b003f5d8756675si9998318pgc.371.2022.08.07.19.23.06; Sun, 07 Aug 2022 19:23:20 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b="ej0Ok/or"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242535AbiHHBhx (ORCPT + 99 others); Sun, 7 Aug 2022 21:37:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242438AbiHHBgf (ORCPT ); Sun, 7 Aug 2022 21:36:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 309F2BE02; Sun, 7 Aug 2022 18:33:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 89B9560CF7; Mon, 8 Aug 2022 01:33:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3008BC43142; Mon, 8 Aug 2022 01:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659922410; bh=4pNbcfBY7sSXixtKDEXaS8TRXL9OvdOoDNaQXO+z7ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ej0Ok/orkWtSURumxuxWcRBdC5cEDPzI5EckSsPD3wgm0szj0DRBNPRSPtLgl3Wxc lTvVDsKGYc+dflzvqvDG6gvUMDQ3/vsLyeIARPEZ3IcQ/8FV9uZcCPKFA6TCRvmV6v G96b23ciCF78j1R6CelQXDKms5tHXXdcYBIYo/Bspvcz3SKocsi3CgloMwPONqqj0u HG18rsWXzsxjo2bmsqWszU63MVWM5b5SDc/hwUHHhwUBqxZ8uhoBMIbmAnT0hAWndA aarquRcFWoouB0ydEVplwb2fpBNMCtHVdBLo3yyzYRVtok4721/4ZiXb8bEfgHhxj/ gsRp3Li83saqA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Guenter Roeck , Sasha Levin , jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH AUTOSEL 5.19 51/58] hwmon: (sht15) Fix wrong assumptions in device remove callback Date: Sun, 7 Aug 2022 21:31:09 -0400 Message-Id: <20220808013118.313965-51-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808013118.313965-1-sashal@kernel.org> References: <20220808013118.313965-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Uwe Kleine-König [ 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 Link: https://lore.kernel.org/r/20220725194344.150098-1-u.kleine-koenig@pengutronix.de Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- 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