From patchwork Tue Jan 23 15:09:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 190997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp398146dyi; Tue, 23 Jan 2024 07:09:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5rp4ZST2/a0NiPVQMdD3lmeiOhU/JwX+eonyItdAZicOEqwE6wc94m+9cB3TmCT8R9LH4 X-Received: by 2002:ac8:794c:0:b0:42a:5060:8e27 with SMTP id r12-20020ac8794c000000b0042a50608e27mr1005093qtt.48.1706022597252; Tue, 23 Jan 2024 07:09:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706022597; cv=pass; d=google.com; s=arc-20160816; b=IDTJr57NsZInNUIGaiX3ACoqA9HSTWr62bnmea0xaHoLznx4fuLkBhx6GuDUHG4wXy f1Ki7HoyRP9JGbkmFVuNpH5zP975qgMVSX2viq6TZHTIuoZlDhrbIf63a47dzJr1zqoE N3nqjOyAFwKSihU/oMxP1PNQ2RGVjw+kjWIV3k89kHbwQL1Bwp1+LqgaNIL1Db4GntPG miCJiPjcPo0hWqbCm6d4bXYjUK9Dgf5SiLuQ1pQ95oTcdtk44jB2Fl2hU9y5uHMDt7A2 vAf5ggvtT3+WA/cihTcmeyDOH/mVLv9Y7PceM1AKuFeu0iDjyq7eu3iMZ6vQvacD7wfO OwjA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=VbxBxCWrIh0zrQFy85sWtt5gQmurWQ5SJD+FOeS70nI=; fh=6h784S57cSWbC/QCurcAvBvZChdyzW5HGNlWMF29gjU=; b=xQftgGOmDIZs8t/S9JtIgyShb8pOKTpsZaOcdYajJ789IeA4DWujkgNSCrH3+QNf40 B95e9hnyQBCRfxJAymMz4mBTPa5x2abYmiVn1Cem/cdnCFQSl+NOw4MaffB9XrwaPZPJ nCMvOmiJEbTVRqrgObt7PO9vrY2PCzw3R0mr3GfUGihlJ3iqbP+HwEPSepXN0M5KGJ3T eeKm/XWm56Kgg1zuLAdIgQGqTGnTJdAgidChSgG0+6uCgw7QThI0tI3f322Izv6Q1mgQ jDIEqFm1h4psWx4JgFNFpA7rywpr4BDckDiKVs39cqKF+mh4cGrolwy6qswseidkURBv SDAQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=KsEleuV8; 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-35506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35506-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n11-20020a05622a040b00b0042a1c757654si8185477qtx.626.2024.01.23.07.09.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:09:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35506-ouuuleilei=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=KsEleuV8; 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-35506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35506-ouuuleilei=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 0E2B91C20F44 for ; Tue, 23 Jan 2024 15:09:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE9665FEE7; 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="KsEleuV8" 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 BCD045F55B; Tue, 23 Jan 2024 15:09:26 +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=1706022568; cv=none; b=KMu+X4/wT22jiDF0EuHeT+x7qVwaAZ4d5DI3ZaDufIm/kzVu0wqY8YjAptojR8/O5TA1hTpbWj7VQgBqp567za2nmAmW9YzzXzyAKxo/oBQ6oRTlcVZdbI9+2ELJUm6h1MfrwKzxciVskvPeFdemGrwodCMGFsBGqPcf0XZyTvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022568; c=relaxed/simple; bh=zdN9AWx3mn6BQG7Qefn2YsGqa539WPtGvVDiINeK+1o=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=tCpLz3zkHmZUB4mJTHPYkqO70Ak2qPjMfKdvwO2Ii3Lvz2nO6xWWyKUiCajHgAaEM+bt0fjEWNwEh0Q94oV64vSbuPSqXUTqzdc1z/pHilOScsK56wuyzQfMG8y1D4KUGeoB5++KTDfz5hpPEWPEZNjp3j0l6riP1mcV4AR7M0E= 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=KsEleuV8; 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 fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 40NF9Gib071713; 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=VbxBxCWrIh0zrQFy85sWtt5gQmurWQ5SJD+FOeS70nI=; h=From:To:CC:Subject:Date; b=KsEleuV8lZ0JP71WGyWQW8tp/ZhZn9xB7Rkc3M30j3hDMr7v9mYrpAeN3lcsA+aLH WFW3bYSUBmV3bU7Vh1rpLum/vsZrxFqlnxfuxdASeHQXDBE+4gOdp3n6NpsBJo2+EH I89aPTQyzMfRB3PzRvRWTPHHaJq2szyMWVGBWtz4= Received: from DLEE111.ent.ti.com (dlee111.ent.ti.com [157.170.170.22]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 40NF9GiO075195 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Jan 2024 09:09:16 -0600 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE111.ent.ti.com (157.170.170.22) 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 DLEE104.ent.ti.com (157.170.170.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 40NF9FE4128205; Tue, 23 Jan 2024 09:09:15 -0600 From: Andrew Davis To: =?utf-8?q?Pali_Roh=C3=A1r?= , Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 1/5] power: supply: bq27xxx: Switch to a simpler IDA interface Date: Tue, 23 Jan 2024 09:09:10 -0600 Message-ID: <20240123150914.308510-1-afd@ti.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788894350815286696 X-GMAIL-MSGID: 1788894350815286696 We don't need to specify any ranges when allocating IDs so we can switch to ida_alloc() and ida_free() instead of the ida_simple_ counterparts. Signed-off-by: Andrew Davis --- drivers/power/supply/bq27xxx_battery_i2c.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index 3a1798b0c1a79..86ce13a8ab9dd 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -13,8 +13,7 @@ #include -static DEFINE_IDR(battery_id); -static DEFINE_MUTEX(battery_mutex); +static DEFINE_IDA(battery_id); static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data) { @@ -145,9 +144,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client) int num; /* Get new ID for the new battery device */ - mutex_lock(&battery_mutex); - num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL); - mutex_unlock(&battery_mutex); + num = ida_alloc(&battery_id, GFP_KERNEL); if (num < 0) return num; @@ -198,9 +195,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client) ret = -ENOMEM; err_failed: - mutex_lock(&battery_mutex); - idr_remove(&battery_id, num); - mutex_unlock(&battery_mutex); + ida_free(&battery_id, num); return ret; } @@ -212,9 +207,7 @@ static void bq27xxx_battery_i2c_remove(struct i2c_client *client) free_irq(client->irq, di); bq27xxx_battery_teardown(di); - mutex_lock(&battery_mutex); - idr_remove(&battery_id, di->id); - mutex_unlock(&battery_mutex); + ida_free(&battery_id, di->id); } static const struct i2c_device_id bq27xxx_i2c_id_table[] = { From patchwork Tue Jan 23 15:09:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 190999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp398428dyi; Tue, 23 Jan 2024 07:10:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlKe/k/BPyksFsXS3uTppnel3vMILOlPNkWrXwkl/C1Ay+1jmIP0f50Ys9vz2PJPsSBQJH X-Received: by 2002:a17:906:ca56:b0:a2e:51ab:8a2f with SMTP id jx22-20020a170906ca5600b00a2e51ab8a2fmr404775ejb.73.1706022619803; Tue, 23 Jan 2024 07:10:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706022619; cv=pass; d=google.com; s=arc-20160816; b=ec0qPOxR93LS51onnI5Aj5yVerDM1jwa3dNDgG9po3jsv+sGOtMWAZyovJ+xucnbzV soRuL0Jp/rcfBBJnV7D7KhTZOFYZpeqjqmiesJoOj9BEx8DRePcf5YuBaS3uLcMTFYHX JkGdW8B0GjvYnjDr0C5WwRGedDWfXuMsLnGgako2A4PllryarFdx4qKnZbQNPuWUwxwl 0Sd3UgjA1ZketSxWDB33I21+5KzephEta+Rc3LTXQK7tscU4tpNFlrGjmKWND6LExJDd YENwcYqrfww+e1s/Dj9uJQAyuQ0ckZPW9nYsfvmVbWqZb2Uqf6DgUkaNuA2MNF73ErfS 7YkA== 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=U8z/mm6tvX41IgL5zXvGtQyrqKekNbTjdaLCuQcgzpg=; fh=6h784S57cSWbC/QCurcAvBvZChdyzW5HGNlWMF29gjU=; b=bw+Hy72Jzv2l/VKJ0cy0qWQgXwS0+/B1S02Z+2k7IEWxHXA2hx5mVzqJij3rN6kCKp ijXBFXKRDbmhy8TKpym/WwVMcwe7qH7gjT4pBS+FYrxRHPNP6OGnt6HLLWhMBnayxDl4 a3G73vt3Rm5CGa3qwFFPQQ0+FbqbbwoLNU3fOgoI9IpdWWWOH0y7IOcxCccj0AeT9vc2 75cdbVbdYxMo0njrgnWwJIx+li9sJHv1R/z4jQzQUnnrJ+vrxNjmWBF6T+lFL9h1DWW4 z4JTJLFP4yPjTLTVMA0ewEMc5XTuPiBAkhKAO2T4dw7mhyItToVgBybhOt0YtZmGgs5S hJrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=jKbsqhg4; 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-35508-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35508-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i3-20020a170906250300b00a2ca9f3ce99si10877712ejb.661.2024.01.23.07.10.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:10:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35508-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=jKbsqhg4; 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-35508-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35508-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6A2861F244A0 for ; Tue, 23 Jan 2024 15:10:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E35060246; Tue, 23 Jan 2024 15:09:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="jKbsqhg4" 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 506555FBA4; 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=1706022570; cv=none; b=Cn20BWazz7/vT7olKdTthiBbp35rHwQxZFqaOEJ599WVyCD23/P+jgE/OPPfLIe8fv/klq/3QYj9eHN2pmI2Q5ApBWIozNYozx9t/Ws9aUmvi5daVK2g+nRXSN2V5TtOreUY+/+rfp6T+u9PGeoWrRxqwAF7gjlmp+47yrSia/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022570; c=relaxed/simple; bh=iKB5PHhQJrCVqYkttAams/e+uE3rZowr9sAkkNMLjqw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HC//ax2jaEnhsJpAadDj97W4nkgWQmJ7Yh/UcGZbO/tXKjnav9jL1JElaRp7iKiw5sXDDFutvEWGhGd2lHWl0xlw4yAMTybM0bpv84WP1Y/G1kqslRxJCL4Njqle8lpOyidbcga+yHMdDpzhU20bgZm1KnID6F/wawdkjWsr+J8= 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=jKbsqhg4; 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 fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 40NF9Ghc071718; 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=U8z/mm6tvX41IgL5zXvGtQyrqKekNbTjdaLCuQcgzpg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=jKbsqhg4C1Tu5lYQWhHsNyRK8qFLDXBU0N3enrghanw+IiV1VHRH1EKSkKZbAKv1k sHoIKOjB2jneX+ItMas+VOzuftsD+S6mY026eR18RlPuCx695NvrIIEUqNeYNXgM8B yL6Rh1Tb9YcmxJdLTe1CLtFTVjH9rA4v5qVQBjk4= Received: from DLEE111.ent.ti.com (dlee111.ent.ti.com [157.170.170.22]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 40NF9GSE075202 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Jan 2024 09:09:16 -0600 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE111.ent.ti.com (157.170.170.22) 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 DLEE104.ent.ti.com (157.170.170.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 40NF9FE5128205; Tue, 23 Jan 2024 09:09:16 -0600 From: Andrew Davis To: =?utf-8?q?Pali_Roh=C3=A1r?= , Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 2/5] power: supply: bq27xxx: Add devm action to free IDA Date: Tue, 23 Jan 2024 09:09:11 -0600 Message-ID: <20240123150914.308510-2-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 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788894374465525276 X-GMAIL-MSGID: 1788894374465525276 Use a device lifecycle managed action to free the IDA. 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_i2c.c | 35 +++++++++++----------- include/linux/power/bq27xxx_battery.h | 1 - 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index 86ce13a8ab9dd..019f29d13d28a 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -135,28 +135,39 @@ static int bq27xxx_battery_i2c_bulk_write(struct bq27xxx_device_info *di, return 0; } +static void bq27xxx_battery_i2c_devm_ida_free(void *data) +{ + int num = (long)data; + + ida_free(&battery_id, num); +} + static int bq27xxx_battery_i2c_probe(struct i2c_client *client) { const struct i2c_device_id *id = i2c_client_get_device_id(client); struct bq27xxx_device_info *di; int ret; char *name; - int num; + long num; /* Get new ID for the new battery device */ num = ida_alloc(&battery_id, GFP_KERNEL); if (num < 0) return num; + ret = devm_add_action_or_reset(&client->dev, + bq27xxx_battery_i2c_devm_ida_free, + (void *)num); + if (ret) + return ret; - name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num); + name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%ld", id->name, num); if (!name) - goto err_mem; + return -ENOMEM; di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL); if (!di) - goto err_mem; + return -ENOMEM; - di->id = num; di->dev = &client->dev; di->chip = id->driver_data; di->name = name; @@ -168,7 +179,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client) ret = bq27xxx_battery_setup(di); if (ret) - goto err_failed; + return ret; /* Schedule a polling after about 1 min */ schedule_delayed_work(&di->work, 60 * HZ); @@ -185,19 +196,11 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client) "Unable to register IRQ %d error %d\n", client->irq, ret); bq27xxx_battery_teardown(di); - goto err_failed; + return ret; } } return 0; - -err_mem: - ret = -ENOMEM; - -err_failed: - ida_free(&battery_id, num); - - return ret; } static void bq27xxx_battery_i2c_remove(struct i2c_client *client) @@ -206,8 +209,6 @@ static void bq27xxx_battery_i2c_remove(struct i2c_client *client) free_irq(client->irq, di); bq27xxx_battery_teardown(di); - - ida_free(&battery_id, di->id); } static const struct i2c_device_id bq27xxx_i2c_id_table[] = { diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h index 7d8025fb74b70..b9e5bd2b42d36 100644 --- a/include/linux/power/bq27xxx_battery.h +++ b/include/linux/power/bq27xxx_battery.h @@ -61,7 +61,6 @@ struct bq27xxx_reg_cache { struct bq27xxx_device_info { struct device *dev; - int id; enum bq27xxx_chip chip; u32 opts; const char *name; From patchwork Tue Jan 23 15:09:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 191000 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp398541dyi; Tue, 23 Jan 2024 07:10:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3sIV/WUVuAuYFpdCbv2vE++/yx856cEBdJRD5nw1yzLCYoC1/XIY5nAYMbax8alrI1bpW X-Received: by 2002:a05:622a:1046:b0:42a:3ee5:d8e1 with SMTP id f6-20020a05622a104600b0042a3ee5d8e1mr1208877qte.26.1706022628494; Tue, 23 Jan 2024 07:10:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706022628; cv=pass; d=google.com; s=arc-20160816; b=yfu4c1I6HxwJUSeXzA2JvXNZ/4IxVHI51Vcv4EP99wuCdnNJYMFf49JWv9EPXXLRu4 6EposXMS6VyOUKODILvw2/B71zGQmhH+PeeiFE1XinXX0E/OAK0cMPl404fnqQUNmaW2 yfh65SeeBCHfE6OeRoAT6xGCUhVxKILilOymKDakbnkAdKuccpITcUrfBuO7BGh7m/0b tHLzQ4jcNgPPMoauKXykIkusXi/MhtWgcmWCN3H24EcBFZhTk8Aras9Xd+9v+BecMUh/ w635d5ivz/0RuWzTHYp2vRr5uidWcmg3G67MA3pZh8F0qzY2bDapkm3vukgbVqqU1jl+ qEdg== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35507-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 22-20020ac85956000000b0042a377def64si6192147qtz.418.2024.01.23.07.10.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:10:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35507-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35507-ouuuleilei=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 3C0ED1C23014 for ; Tue, 23 Jan 2024 15:10:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 768FD5FF16; Tue, 23 Jan 2024 15:09:32 +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_Roh=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 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788894383896354363 X-GMAIL-MSGID: 1788894383896354363 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); From patchwork Tue Jan 23 15:09:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 191001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp404685dyi; Tue, 23 Jan 2024 07:18:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdIDXiURVAC1u+9bhHF3loS+8+MtdrO8pIP1XxHDqbTzrbVUlnM/iONHA2z0l7QhHceRmj X-Received: by 2002:a17:90b:194f:b0:28e:850e:7e87 with SMTP id nk15-20020a17090b194f00b0028e850e7e87mr8220753pjb.41.1706023121499; Tue, 23 Jan 2024 07:18:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706023121; cv=pass; d=google.com; s=arc-20160816; b=Y3bZXzd+qPYtBwjSrMY4Pu6xCntiI/quSf9orTSzhzvq5pCzLSqNLVzDvyAbB9FnD7 PsaW5SzrG7/n1DoaQpuA/jHtGEj1GiTelqxxfZmrZ83XcPtnJRytmnhm4YPR8UR/CZ5y HVyuZzdy9CwfUTTLC/XG9d0dOk5H+5AU7Bo+5AWPy+YK//n0tk/mfESzQxY6ssbbiwTa 5WT177nMir/N/CSB4Fa3QNngHJPkDn+Gur/JzApOMmG+3nk6gfT7JciKxCAx9iCjXzMb KISo1antgAdmiOVtAZYZNU9vY14Jt5UUdq/f7MNmFlNg6uB/nyyot+VdZPEX1+t1/RMM KKAw== 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=XBxIuTPwoOzGfB8OHKOyASLbyJf1pzgDv1spHNZWZnA=; fh=6h784S57cSWbC/QCurcAvBvZChdyzW5HGNlWMF29gjU=; b=XJe8JNqXFwl5QzBpxrqu1VVUISPb4ZJ7wwzpUAVm7FlseOepWY3n6NKbwck6QJh3vq 1hpF0Iw0qA7C/a9mCFkgYWahuN+or3214nDWzKXvk4S7L1e60m75YO3SCmJmuRv1xXO7 xAu5tF+KlrRf/7b/zv2KtjbigHmNwaPDv75NXGwHV/gG9xliPRpxn9HYfZcIplJl7ifu Ye5MEO+1/cpkcdsoHEeKhVgE6t3O6D1rRNiaoXIZz8H/kgyLBciVgEjWlxlrvwv22bE5 qPWyIGw35x2vljjUWXzVzTqSkGxpGoNuYEWauUA12gRvC9+lfbfE7u+jvvrGVmL/lncg 6ygA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=NtZoKrAz; 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-35509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35509-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y2-20020a63de42000000b005ce04177ad2si9867190pgi.386.2024.01.23.07.18.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:18:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=NtZoKrAz; 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-35509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35509-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 986FF294DD6 for ; Tue, 23 Jan 2024 15:10:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CC1F604BD; Tue, 23 Jan 2024 15:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="NtZoKrAz" Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 A15435FEFF; Tue, 23 Jan 2024 15:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022573; cv=none; b=cdPX6AhALA1zVXAD2T/U0fvxfXDc6AkUOrnbEcWOOm/P+iSbhOicy7vJMp7K/WV23QypW7H3+JUyRAybhl1Xc0q4TLuV8pCCjqqU3raWGwn7XVLD9t1lTiYqWIzGfIWDVsWly5kUH4WVebzlYinvzK8M/a6FLFgTpzqSi4WRJcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022573; c=relaxed/simple; bh=TR+JZ2LAe+2IY3y6XWtBU3J7Q30KfFb19RmcJWo9PP4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uC8NTff8/5jKMgwAB5LaY2y7Y5LnB17IdNIYBcWf0+cdvE2mKpy+HJRcfpybXQIloWGDHTCsBHK1+0yqPrTK1l3RVszVsraXRD4dAUEz2+TDpWr4uV4LBWFj5Z8rH9bj50kAO6sT52up4oMqpQQ27/EKuM1RLJIAkr9U1Hocr+k= 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=NtZoKrAz; arc=none smtp.client-ip=198.47.19.142 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 fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 40NF9Hlr057182; Tue, 23 Jan 2024 09:09:17 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1706022557; bh=XBxIuTPwoOzGfB8OHKOyASLbyJf1pzgDv1spHNZWZnA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=NtZoKrAzdeflXcYyaO4MnxJWiDUedOzLGDYD+cHGriwdfFifV1VzWWxS3l9/CXAxV rUT6ss1YkQQMq/jsZLUE6ubRXXBEeSZ9jTikXLJmQERnucifNazjGWjjrpRMYQfx1C xXdcMLzRtqzrrY0eSQDrBWtzMAp808iOyVyyVjqk= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 40NF9H8O075316 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Jan 2024 09:09:17 -0600 Received: from DFLE112.ent.ti.com (10.64.6.33) 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 DFLE112.ent.ti.com (10.64.6.33) 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 40NF9FE7128205; Tue, 23 Jan 2024 09:09:16 -0600 From: Andrew Davis To: =?utf-8?q?Pali_Roh=C3=A1r?= , Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 4/5] power: supply: bq27xxx: Use devm_power_supply_register() helper Date: Tue, 23 Jan 2024 09:09:13 -0600 Message-ID: <20240123150914.308510-4-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 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788894900777691872 X-GMAIL-MSGID: 1788894900777691872 Use the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths. Signed-off-by: Andrew Davis --- drivers/power/supply/bq27xxx_battery.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index d3b6327b16b56..2bf5e007f16b2 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -2140,7 +2140,7 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) psy_desc->get_property = bq27xxx_battery_get_property; psy_desc->external_power_changed = bq27xxx_external_power_changed; - di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg); + di->bat = devm_power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg); if (IS_ERR(di->bat)) return dev_err_probe(di->dev, PTR_ERR(di->bat), "failed to register battery\n"); @@ -2168,8 +2168,6 @@ void bq27xxx_battery_teardown(struct bq27xxx_device_info *di) mutex_unlock(&di->lock); cancel_delayed_work_sync(&di->work); - - power_supply_unregister(di->bat); } EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown); From patchwork Tue Jan 23 15:09:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 191002 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp406852dyi; Tue, 23 Jan 2024 07:21:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjIL+tGoueH3NzeMdbNLErM2c8T9TuruBWwdTKZaFDnUOylyDBKayw+hA5Fn1ozKse4lz/ X-Received: by 2002:a05:6a20:2729:b0:19a:43a1:5034 with SMTP id u41-20020a056a20272900b0019a43a15034mr6037364pze.51.1706023316977; Tue, 23 Jan 2024 07:21:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706023316; cv=pass; d=google.com; s=arc-20160816; b=W0Cl2We8N8SKyVxBkjBR/IGZTBiAWEO/5DUnzSN7cd9+xDOIcWgaMbIrFLifLlbhTq WZ8k0NwMpPKqI7nU5906yUwzK0di7MxAtjDJB0xXzg74pVbCtGNLUEhifORFuSDcPmpn 3ClwMrOwgAO/xUx8dzsum4J53tQAaIQJaBpNWUMSIra++MX+2ecFBOR4/IvW8Rh5jzac 60hjZjei0GKaV+pOj+JRbz7I4i+QQnrw1kltutKGyrKgA9jc62OQh91+Eo2eHCzaDcul /iiYek0TXHZmVT8GIj7ikuwuaHNKbqMRxoPgHBqyr0e1B9RQnBfW8RjzpMPMl+c9CJG3 vCJQ== 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=cQO8AG1imo5nzL+9z6gHt9JLJg6ArVzr0rRl02yudVg=; fh=6h784S57cSWbC/QCurcAvBvZChdyzW5HGNlWMF29gjU=; b=SHCJehxjLSl9+FgcY7G9Z5pvtwrFSgVgMb/VEOrJcg4fheSrCYu3o98lFfRCmskJAG DnMQ6EC79N4yT0cYNf8yuv9VAKxlpldqz66UgRaGOngrL9eEdU6MlfGTu5zrbPlUZgye S0wzoC3LhNDHzbTCF46EBgP1pQ1rMAoK1YabZHrtviyKETbO7xeROs9B9sulSjUygygm rwPKsJYsDg8jVKYLdF1U/IhQsrAswnd4XyTgrSEPdz70FPEZ6flE/ojfFwDaiiEqr/H9 kln9wTLYWrHTy5+sBnaHZESnPp8KZB+5QNHijGHIFgUE9toF9zVsPnm0PiubBYbWQFyn fEzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="BBdgU6u/"; 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-35510-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35510-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w24-20020a634758000000b005cecf2bfa45si9912699pgk.378.2024.01.23.07.21.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:21:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35510-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="BBdgU6u/"; 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-35510-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35510-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BC76DB2613A for ; Tue, 23 Jan 2024 15:10:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6B01604C4; Tue, 23 Jan 2024 15:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="BBdgU6u/" Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 A14FD5F55B; Tue, 23 Jan 2024 15:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022573; cv=none; b=JavfFm1sCZWOA8NquMh3hSDj/bku16C2YBACS1WbCZe6/2I6pIgEzCmyRw1n7g6YoRzlr85sGYgO+3muJe4dsCQpBGxyAqjb1Gt5O8/LBVEGVNeZA4JDdyGAZTxEVXAlt41nRHjUD6k8YIGY1aMW4lCcG9rzheeTeFO9XECX+nY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706022573; c=relaxed/simple; bh=OmY52dAJtLk+DFU1yWAq3MiNuVQtFcHtaahSuJx1y14=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dfoILR6mTuiGLfQB2XiUP+rHSG4GSLTHX3WOkGpRO+JTnHu84UWDMgtVRoc+//KCH1+nizUgyZ52eFyx2jFfcLg5A0gBOUgdbEKAZLi069iROxKrKHGEqMoTcf/5rubhx25hIl/I43VfEJR3qdrGoteCTmbCtM9LoKMaSOWCDZE= 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=BBdgU6u/; arc=none smtp.client-ip=198.47.19.142 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 lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 40NF9Hr8057186; Tue, 23 Jan 2024 09:09:17 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1706022557; bh=cQO8AG1imo5nzL+9z6gHt9JLJg6ArVzr0rRl02yudVg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=BBdgU6u/z+LChgmxrc5nlwoJaikDTChA8orEgn51eKY/21RZg0+jjF9RTptBCQuk+ inu7Z+X4efNUluSmyiL4wA7xOb8NqJXzDa0eaQUKgcOfQU5yavn/uVq4ysgDl0GSI5 IDfv2R8GjaOnnB8ILEeJA4Ecldgq+2bVTdqO/Cj8= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 40NF9Hjg029596 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Jan 2024 09:09:17 -0600 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE112.ent.ti.com (10.64.6.33) 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:17 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE100.ent.ti.com (10.64.6.21) 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:17 -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 40NF9FE8128205; Tue, 23 Jan 2024 09:09:16 -0600 From: Andrew Davis To: =?utf-8?q?Pali_Roh=C3=A1r?= , Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 5/5] power: supply: bq27xxx: Move one time design full read out of poll Date: Tue, 23 Jan 2024 09:09:14 -0600 Message-ID: <20240123150914.308510-5-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 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788895105264826976 X-GMAIL-MSGID: 1788895105264826976 This value only needs read once. Move that read into the function that returns the value to keep the logic all in one place. This also avoids doing this check every time we read in values in the device update poll worker. While here, correct this function's error message. Signed-off-by: Andrew Davis --- drivers/power/supply/bq27xxx_battery.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 2bf5e007f16b2..363428530ee60 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -1595,17 +1595,24 @@ static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di) * Return the Design Capacity in µAh * Or < 0 if something fails. */ -static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di) +static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di, + union power_supply_propval *val) { int dcap; + /* We only have to read charge design full once */ + if (di->charge_design_full > 0) { + val->intval = di->charge_design_full; + return 0; + } + if (di->opts & BQ27XXX_O_ZERO) dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, true); else dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false); if (dcap < 0) { - dev_dbg(di->dev, "error reading initial last measured discharge\n"); + dev_dbg(di->dev, "error reading design capacity\n"); return dcap; } @@ -1614,7 +1621,12 @@ static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di) else dcap *= 1000; - return dcap; + /* Save for later reads */ + di->charge_design_full = dcap; + + val->intval = dcap; + + return 0; } /* @@ -1865,10 +1877,6 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di) */ if (!(di->opts & BQ27XXX_O_ZERO)) bq27xxx_battery_current_and_status(di, NULL, &status, &cache); - - /* We only have to read charge design full once */ - if (di->charge_design_full <= 0) - di->charge_design_full = bq27xxx_battery_read_dcap(di); } if ((di->cache.capacity != cache.capacity) || @@ -2062,7 +2070,7 @@ static int bq27xxx_battery_get_property(struct power_supply *psy, ret = bq27xxx_simple_value(di->cache.charge_full, val); break; case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: - ret = bq27xxx_simple_value(di->charge_design_full, val); + ret = bq27xxx_battery_read_dcap(di, val); break; /* * TODO: Implement these to make registers set from