Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp534924rdb; Tue, 23 Jan 2024 07:09:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMMYOHb2h3w+v21+AzZZaF5h9CdPySKEGEbL1nRdvYQ8plHfi7FIM1EDLSzVKWlqhEul9T X-Received: by 2002:ac8:5cc6:0:b0:42a:5859:38a9 with SMTP id s6-20020ac85cc6000000b0042a585938a9mr226554qta.107.1706022591484; Tue, 23 Jan 2024 07:09:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706022591; cv=pass; d=google.com; s=arc-20160816; b=V+a2HjazNemRYYjKIFwflHnY2QVmiB/9zxy99wlviUL9kY50SRRcAKpfb8ebdek5wz c1ZqbFim9s0a5BQdEsWOL/btjrxWaU6d0CJmmAdAJ98AG8mKNwn8tnM3au6I86Qq1ckY IzXLL1TMQTaZ0ukmEucy8Wot0AVolAgrvovN6Y/As5RlFrmEDBfkEF6yBTuPnH73nFR7 8aKfQuO1y0xo7yFutvStYhPZov5rjDLDWt6naWNMl8P3N1KABk2s030Rp8RC8pVopJu7 6jTO1TUBSFN/+hwdA8Tx2wSssWnvX10iMOwH3e1qwiqODuc7cBej2b+TpWQpegSa0dsI rqaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=11mrXH87jJGLlmaEk7O3hQevdSFbmybFJkpPSU3t3Dg=; fh=6h784S57cSWbC/QCurcAvBvZChdyzW5HGNlWMF29gjU=; b=y7BIdCSDIro3SUKoqGI68qstKiAE1dwdM59YyC9VjBDG9y3VnH8hCRIaQeCDZPEI92 hGLU6QnI2uvO4MtFjVEE3W2OOGzVkaGD0tdCF+hecoZLERa02WCZ09xoJ02Bz4Xpd8MP KF1QO81aN/sTqmghGLR6ihrdoN2+038Vv1JQGyZHmnBo0bvInN6/o1ivli4GpwTSW0D3 JqPo382aHm45AwTYyvG6oz5s+SjM3Ayd6PxC24uG6u29e2bFT7dcNzdRcaPCnVQryxSg Hz6idlhdf69knqurG0qDhogxDkDzK7adp0s9JHcEjdzfZxb8wXQYFknS7yZvIqBv5e9q 9m6Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Zmr98Cno; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-35507-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35507-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 9-20020ac85949000000b0042a4bfc4e6asi2125570qtz.452.2024.01.23.07.09.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:09:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35507-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Zmr98Cno; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-35507-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35507-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3EE3C1C20AE9 for ; Tue, 23 Jan 2024 15:09:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 996135FDD2; Tue, 23 Jan 2024 15:09:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Zmr98Cno" Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 506945FBA6; Tue, 23 Jan 2024 15:09:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022569; cv=none; b=jolHawn+azd9CagB6huCHfQba+7+HjjQ60vfSc0kl4dFni+Nv/AZOuT3BTerCdkNb19xj+8mq4GAsALcs6+eZd/h73t7XRbBznDMGqOi4PVjyFW/fw0NDn6vhS2NqfalgunhqDyh+ivfEklH+JLQ/zC/6GMeRB9QzRMual0MVes= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022569; c=relaxed/simple; bh=UTIUm4JGGF1yQzAyMxxiGParwPa8ulPNa7PkwXl4NUI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=msjmoA+u2Ub/fe+7ba7VYXIjnjfrO5dJcR/sx8Y3iJjcljxYnkGjiW/Xhx9Hg1JFwEQ44Zd0z+qq/SrMz/tsOdPlgi15VVJv4qloSxYVhCxiNLaa+x8PdBlzoznPd+G9OfRcFrgXn4HCmi1CPTfrRZodV8GQmWSgHz+wZykM/Us= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=Zmr98Cno; arc=none smtp.client-ip=198.47.23.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 40NF9G5N071722; Tue, 23 Jan 2024 09:09:16 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1706022556; bh=11mrXH87jJGLlmaEk7O3hQevdSFbmybFJkpPSU3t3Dg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Zmr98CnoFAvM7QkArWJSg/od1z7hULzc03vqAURbjzl/k7v4F9PAtqVp/vglfmW3C h8xqdFjS28HKwnsgpLT+paD1xXQ95Yhpms1L2nfO9/Fr0xrT9mCwgZsXlmn+xK15Zv wqtSXpXRWylxLESkCBNZFSOE8ppy/Z7BLmnnsSS0= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 40NF9GDH045945 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Jan 2024 09:09:16 -0600 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 23 Jan 2024 09:09:16 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Tue, 23 Jan 2024 09:09:16 -0600 Received: from lelvsmtp5.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 40NF9FE6128205; Tue, 23 Jan 2024 09:09:16 -0600 From: Andrew Davis To: =?UTF-8?q?Pali=20Roh=C3=A1r?= , Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 3/5] power: supply: bq27xxx: Use devm to free device mutex Date: Tue, 23 Jan 2024 09:09:12 -0600 Message-ID: <20240123150914.308510-3-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240123150914.308510-1-afd@ti.com> References: <20240123150914.308510-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Use a device lifecycle managed action to free the device mutex. This helps prevent mistakes like freeing out of order in cleanup functions and forgetting to free on error paths. Signed-off-by: Andrew Davis --- drivers/power/supply/bq27xxx_battery.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 1c4a9d1377442..d3b6327b16b56 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -2101,6 +2101,13 @@ static void bq27xxx_external_power_changed(struct power_supply *psy) mod_delayed_work(system_wq, &di->work, HZ / 2); } +static void bq27xxx_battery_mutex_destroy(void *data) +{ + struct mutex *lock = data; + + mutex_destroy(lock); +} + int bq27xxx_battery_setup(struct bq27xxx_device_info *di) { struct power_supply_desc *psy_desc; @@ -2108,9 +2115,14 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) .of_node = di->dev->of_node, .drv_data = di, }; + int ret; INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll); mutex_init(&di->lock); + ret = devm_add_action_or_reset(di->dev, bq27xxx_battery_mutex_destroy, + &di->lock); + if (ret) + return ret; di->regs = bq27xxx_chip_data[di->chip].regs; di->unseal_key = bq27xxx_chip_data[di->chip].unseal_key; @@ -2158,7 +2170,6 @@ void bq27xxx_battery_teardown(struct bq27xxx_device_info *di) cancel_delayed_work_sync(&di->work); power_supply_unregister(di->bat); - mutex_destroy(&di->lock); } EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown); -- 2.39.2