Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp542682rdb; Tue, 23 Jan 2024 07:20:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkX5/K3sbSJMjt+eDT42EUxx6IAYadvu41LpLslihnxUg7yDONUpRiyr/2R3P1uE6RSfgF X-Received: by 2002:a05:6a20:3d03:b0:199:e6af:30a with SMTP id y3-20020a056a203d0300b00199e6af030amr9921140pzi.38.1706023249899; Tue, 23 Jan 2024 07:20:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706023249; cv=pass; d=google.com; s=arc-20160816; b=0Evlanjvwvg+LGbfieTnlo9O8jsrVDFv+U41FsyAR3SPuEsJdjyIrpQ++eJTPfnJbt x3noI9omGoNHgqypias2JPBrJ57C2tI2Zd5FnizHlufwtHWsGhPjWDRe/NNTCAyRR7yn /ZRuo9sJVRF9656eNNqESvQpZB6vYvrL8dGSUI6Kz27A1VduSkAtmn0ufsCYBVAKYm9t P1bWduQ3sAga73HkDwsEOBGUQpRuxS7E/XPMyzPYkEpLKIxmlH/CIc/TQsIcu4hnKf7D 0/gvEWhzf2MZakdNBcII3TAXKwJRMV8GGdDF3Vuwu0BjTKQ6wNw9DGeSqWcwiyzmTU9Z KNQw== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35508-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k70-20020a638449000000b005ce016cce2bsi671872pgd.190.2024.01.23.07.20.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:20:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35508-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35508-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 00DF4B23C91 for ; Tue, 23 Jan 2024 15:10:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C8995FEEF; Tue, 23 Jan 2024 15:09:31 +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=20Roh=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 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 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; -- 2.39.2