From patchwork Mon Dec 2 21:15:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 13891312 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (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 D1C521DEFE5; Mon, 2 Dec 2024 21:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174126; cv=none; b=LmQ+9rFKgEyhQIyuE3sIvet7cgj5FcLT8Fhb0BVHjFSU44j7IUCLrPQNmXJZvYFjJDntKR73J1ft7GM4VIGIfiMZP+P6TKjuvic1LkXaguQxo7qZHzUurZo2873r4CBfr1IIinmXCwFax566+0a0N6bJ/QKomK6BHmPA79TnvQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174126; c=relaxed/simple; bh=mNc45UUIBnY2zqKfppObvs8Xa0q0wW+mBTnTcKU/KiY=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=rz+tyCRq1AQrm6bFaYqfDlGNCo2g8blxuH3YbFZUSTfmE47wt1Clh9LPUcJcFz80Bys4MLxG+v9/d5jDcA77mnjc2DlpdvIDuzWaKQZuzhetu+WydS1oeGUh0bFcy2gmfe2SQEGcqI5nINIX4czc2hxMrEv7y5uO/cBZVp4Mb94= 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=Th3oikmN; arc=none smtp.client-ip=198.47.19.246 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Th3oikmN" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 4B2LFLMh1522480 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Dec 2024 15:15:21 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1733174121; bh=dIGwGEg/qk6oFqWm5tCTp6Dcc9dKtv2cgkQO45hArK8=; h=From:To:CC:Subject:Date; b=Th3oikmN59pAx8RrzrJIJSSZ5bx5y+0p9rxcGzftwTOm6UvxVJF67hgkF8wwpvD9P 61Mn9NIYwpXi3q5umw9Vzi3olvZ7v7Yn8olWbl2l7Af4fDRZWOHvIdI1+OrATHxB4E Tx87AstmXhYl2uaPByDFZXeRpWyC0bitAMr1TQ+8= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 4B2LFKMK017202 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 2 Dec 2024 15:15:20 -0600 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 2 Dec 2024 15:15:20 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE107.ent.ti.com (10.64.6.28) 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; Mon, 2 Dec 2024 15:15:20 -0600 Received: from fllvsmtp7.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFKgo099805; Mon, 2 Dec 2024 15:15:20 -0600 From: Andrew Davis To: Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 1/5] power: supply: ds2782: Switch to simpler IDA interface Date: Mon, 2 Dec 2024 15:15:15 -0600 Message-ID: <20241202211519.199635-1-afd@ti.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea We don't need to specify any ranges when allocating IDs so we can switch to ida_alloc() and ida_free() instead of idr_*. Signed-off-by: Andrew Davis --- drivers/power/supply/ds2782_battery.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c index 85aa9c465aa4e..10428d781c18b 100644 --- a/drivers/power/supply/ds2782_battery.c +++ b/drivers/power/supply/ds2782_battery.c @@ -63,8 +63,7 @@ struct ds278x_info { int status; /* State Of Charge */ }; -static DEFINE_IDR(battery_id); -static DEFINE_MUTEX(battery_lock); +static DEFINE_IDA(battery_id); static inline int ds278x_read_reg(struct ds278x_info *info, int reg, u8 *val) { @@ -322,9 +321,7 @@ static void ds278x_battery_remove(struct i2c_client *client) kfree(info->battery_desc.name); kfree(info); - mutex_lock(&battery_lock); - idr_remove(&battery_id, id); - mutex_unlock(&battery_lock); + ida_free(&battery_id, id); } #ifdef CONFIG_PM_SLEEP @@ -387,12 +384,9 @@ static int ds278x_battery_probe(struct i2c_client *client) } /* Get an ID for this battery */ - mutex_lock(&battery_lock); - ret = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL); - mutex_unlock(&battery_lock); - if (ret < 0) - goto fail_id; - num = ret; + num = ida_alloc(&battery_id, GFP_KERNEL); + if (num < 0) + return num; info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) { @@ -439,10 +433,7 @@ static int ds278x_battery_probe(struct i2c_client *client) fail_name: kfree(info); fail_info: - mutex_lock(&battery_lock); - idr_remove(&battery_id, num); - mutex_unlock(&battery_lock); -fail_id: + ida_free(&battery_id, num); return ret; } From patchwork Mon Dec 2 21:15:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 13891311 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 966D11DDA0C; Mon, 2 Dec 2024 21:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174126; cv=none; b=CizumGd+Kbeux4k5py8H3F/31KqjQcdRZ/CyxJi5oXjK5gJTwLKgCHAoS0gykEcO/WDyCAzHq0zZ+atobq2WNc4iOl0IxVVK3y0DNY8fJwEe/RhKv2jWpV2uy2ZadZ7QXxlShB1ZDNk+yBNNhZsLlcp5jAJXzWjxBnFw5Ei5el0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174126; c=relaxed/simple; bh=3ncebkoMfB2c4jQJI85u71Oo6G7lqbdbWKatLiOZuBo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BJzs+rKLJ3o2GRHZsiS29aNKRHnICvSEmUXwSmn0SUebRPMmDwBdmlvfqNFzBKYAB2ghlqtkeP7/6Mo0Ik6m4RU4mhpCklsYFL3j4FrUs/jtb9eYkoU3E0oJ74FaqolRaY/YzAIafBlQhaw56U6Jg61UPPt7iNVHi+nQ+3t10Zc= 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=CxAuzfTS; arc=none smtp.client-ip=198.47.19.141 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="CxAuzfTS" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFLRm042457; Mon, 2 Dec 2024 15:15:21 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1733174121; bh=wzPxvMfl6rsFcnkrTUvkGRDue9AJCUJzhDr7f9CnFj0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=CxAuzfTSWrziMID/wm6ZmpPLNiod7vWoJ5fjaz/FCKM4564CXfkeUrdDXMoZJ0VQd vlsyY3tfUVc9UFMYEP7yiZTudPHCFivYZtoEtUlGuGL9EXasKV0qt5bm1Yxu92NGFy y0uQan1TX7DwZQVsuNMJNBh5mQesBBpNdzsF1EL4= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 4B2LFL3Q010171 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 2 Dec 2024 15:15:21 -0600 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 2 Dec 2024 15:15:20 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE105.ent.ti.com (10.64.6.26) 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; Mon, 2 Dec 2024 15:15:21 -0600 Received: from fllvsmtp7.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFKgp099805; Mon, 2 Dec 2024 15:15:20 -0600 From: Andrew Davis To: Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 2/5] power: supply: ds2782: Free IDA with devm action Date: Mon, 2 Dec 2024 15:15:16 -0600 Message-ID: <20241202211519.199635-2-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241202211519.199635-1-afd@ti.com> References: <20241202211519.199635-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea 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/ds2782_battery.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c index 10428d781c18b..28ad11c8f82de 100644 --- a/drivers/power/supply/ds2782_battery.c +++ b/drivers/power/supply/ds2782_battery.c @@ -57,7 +57,6 @@ struct ds278x_info { struct power_supply_desc battery_desc; const struct ds278x_battery_ops *ops; struct delayed_work bat_work; - int id; int rsns; int capacity; int status; /* State Of Charge */ @@ -314,14 +313,11 @@ static void ds278x_power_supply_init(struct power_supply_desc *battery) static void ds278x_battery_remove(struct i2c_client *client) { struct ds278x_info *info = i2c_get_clientdata(client); - int id = info->id; power_supply_unregister(info->battery); cancel_delayed_work_sync(&info->bat_work); kfree(info->battery_desc.name); kfree(info); - - ida_free(&battery_id, id); } #ifdef CONFIG_PM_SLEEP @@ -365,6 +361,13 @@ static const struct ds278x_battery_ops ds278x_ops[] = { } }; +static void ds278x_free_ida(void *data) +{ + int num = (uintptr_t)data; + + ida_free(&battery_id, num); +} + static int ds278x_battery_probe(struct i2c_client *client) { const struct i2c_device_id *id = i2c_client_get_device_id(client); @@ -387,12 +390,13 @@ static int ds278x_battery_probe(struct i2c_client *client) num = ida_alloc(&battery_id, GFP_KERNEL); if (num < 0) return num; + ret = devm_add_action_or_reset(&client->dev, ds278x_free_ida, (void *)(uintptr_t)num); + if (ret) + return ret; info = kzalloc(sizeof(*info), GFP_KERNEL); - if (!info) { - ret = -ENOMEM; - goto fail_info; - } + if (!info) + return -ENOMEM; info->battery_desc.name = kasprintf(GFP_KERNEL, "%s-%d", client->name, num); @@ -406,7 +410,6 @@ static int ds278x_battery_probe(struct i2c_client *client) i2c_set_clientdata(client, info); info->client = client; - info->id = num; info->ops = &ds278x_ops[id->driver_data]; ds278x_power_supply_init(&info->battery_desc); psy_cfg.drv_data = info; @@ -432,8 +435,6 @@ static int ds278x_battery_probe(struct i2c_client *client) kfree(info->battery_desc.name); fail_name: kfree(info); -fail_info: - ida_free(&battery_id, num); return ret; } From patchwork Mon Dec 2 21:15:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 13891313 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 BBC981DF25D; Mon, 2 Dec 2024 21:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174127; cv=none; b=LSmlsqI4Ywfd/CDrmPS43uu/LOC8yuwQZTO1HJStjlXNeaNs5HH+bPo96/8yDnbxXyzeMFRsSDYZVjazt+MjMlr/Y/z0bSUzmO46JoBU2ITibu3dg2guSpeimpY4+DR4NkVDzcM0MF9Ll7KLtZMU1qiG4rWk35ZyzvxTGbVclY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174127; c=relaxed/simple; bh=+KRs5cb5pDNcOrmkVtzoBpHAtS6QlVZC+o3uB+vrlgo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qpacWzn8ZBLRY47LB1EqdGZYuoWkWkRWHmqd6BwX+xrD9eJsz5Vu1fvBN4LE/fWQiBrsEGaNDs8U03kUI4UrA0132KNWFL701kfOLb9abeUF9m/QFFrtKYXnkJ94jhIMZzGcula9fZlRor51qKsgVa0oxa/SMe0jFY82A+EwOCM= 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=tXwTQRXh; arc=none smtp.client-ip=198.47.19.141 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="tXwTQRXh" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFLba042461; Mon, 2 Dec 2024 15:15:21 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1733174121; bh=FSlI7xItPf6A4OyFcddSp1gvlX0oCMs2JHskU3v7+t0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tXwTQRXh+cLdSthP4iBQoFyrEU54QSyOU2y6F4bUytaAl8nWTw/bXRqRcgQNQGNLh dcwkZWqVKifMFIXv48ZprGYaCVUqlX6yYALURFueJKmfbJHY4EnrRYqzL7k/K5N+0n 16gTIgVFmHnEnAlD+lm/b0LBIW68k14hRLxHf/Eg= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFLgb121619; Mon, 2 Dec 2024 15:15:21 -0600 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 2 Dec 2024 15:15:21 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE114.ent.ti.com (157.170.170.25) 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; Mon, 2 Dec 2024 15:15:21 -0600 Received: from fllvsmtp7.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFKgq099805; Mon, 2 Dec 2024 15:15:20 -0600 From: Andrew Davis To: Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 3/5] power: supply: ds2782: Use devm based memory allocators Date: Mon, 2 Dec 2024 15:15:17 -0600 Message-ID: <20241202211519.199635-3-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241202211519.199635-1-afd@ti.com> References: <20241202211519.199635-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Use device lifecycle managed memory alloc helpers. This helps prevent mistakes like freeing out of order in cleanup functions and forgetting to free on all error paths. Signed-off-by: Andrew Davis --- drivers/power/supply/ds2782_battery.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c index 28ad11c8f82de..a72d8c26650d7 100644 --- a/drivers/power/supply/ds2782_battery.c +++ b/drivers/power/supply/ds2782_battery.c @@ -316,8 +316,6 @@ static void ds278x_battery_remove(struct i2c_client *client) power_supply_unregister(info->battery); cancel_delayed_work_sync(&info->bat_work); - kfree(info->battery_desc.name); - kfree(info); } #ifdef CONFIG_PM_SLEEP @@ -394,16 +392,14 @@ static int ds278x_battery_probe(struct i2c_client *client) if (ret) return ret; - info = kzalloc(sizeof(*info), GFP_KERNEL); + info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); if (!info) return -ENOMEM; - info->battery_desc.name = kasprintf(GFP_KERNEL, "%s-%d", - client->name, num); - if (!info->battery_desc.name) { - ret = -ENOMEM; - goto fail_name; - } + info->battery_desc.name = devm_kasprintf(&client->dev, GFP_KERNEL, + "%s-%d", client->name, num); + if (!info->battery_desc.name) + return -ENOMEM; if (id->driver_data == DS2786) info->rsns = pdata->rsns; @@ -423,19 +419,12 @@ static int ds278x_battery_probe(struct i2c_client *client) &info->battery_desc, &psy_cfg); if (IS_ERR(info->battery)) { dev_err(&client->dev, "failed to register battery\n"); - ret = PTR_ERR(info->battery); - goto fail_register; + return PTR_ERR(info->battery); } else { schedule_delayed_work(&info->bat_work, DS278x_DELAY); } return 0; - -fail_register: - kfree(info->battery_desc.name); -fail_name: - kfree(info); - return ret; } static const struct i2c_device_id ds278x_id[] = { From patchwork Mon Dec 2 21:15:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 13891315 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 9872B1DF270; Mon, 2 Dec 2024 21:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174128; cv=none; b=FIVSc1X4ifgGgq6otZpdA2NMVB0vcZTlIJnlDjCPGmk60WuRtRJ64txcXu1s/O8Lu7gl30sA3LHCSX8d7zXZmbucc3vub9kmyKAu5zi4IUdoLgnjXkHzT4/rI3WV5b8S8c95k8Wr3O1xW2Z3VhoWIHl71N668yvXZv3qIlLyoUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174128; c=relaxed/simple; bh=NdJ0yXTxTKVWot4f4JMxdCfyaWCHM1+Od7JimNuxcHM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rNOsMJdesHlEYagJ0g6upLlaomff5/sd6g4RY9ljOABFjk4OSJec0969JliRvhGoSpW27bFHbQl3PiF56QlTmxqki2pQO/xE0nLK9x/BkC5fqYVEWL0YaglLiFpOeMD5R8MfhiVeaTYxc1WaHKuxO6mKoHjvmcbHdBN+6vGe8Rs= 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=t7g01go/; arc=none smtp.client-ip=198.47.19.141 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="t7g01go/" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFLfW042465; Mon, 2 Dec 2024 15:15:21 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1733174121; bh=2JjsfL/WpGUMsb+xrY8eVOUuQ1g+JVXvcYE89y86t3Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=t7g01go/RmuXJCfAeqbr+KattNjlag1gyE+KBhul8w+yGjpGqKD11AXmgoJpTruu1 TunvD60B48z2Uca/iGeHzYP6LUgQpgoN/NeEUo2kds5BXaw409SGmNi4fnlqpW+81w P4RlkY8HnYDcPhe5MSoMVoNtse9iOT4CwTRH8PwE= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 4B2LFLcI010178 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 2 Dec 2024 15:15:21 -0600 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 2 Dec 2024 15:15:21 -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; Mon, 2 Dec 2024 15:15:21 -0600 Received: from fllvsmtp7.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFKgr099805; Mon, 2 Dec 2024 15:15:21 -0600 From: Andrew Davis To: Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 4/5] power: supply: ds2782: Use devm_power_supply_register() helper Date: Mon, 2 Dec 2024 15:15:18 -0600 Message-ID: <20241202211519.199635-4-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241202211519.199635-1-afd@ti.com> References: <20241202211519.199635-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea 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/ds2782_battery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c index a72d8c26650d7..ea687b9703314 100644 --- a/drivers/power/supply/ds2782_battery.c +++ b/drivers/power/supply/ds2782_battery.c @@ -314,7 +314,6 @@ static void ds278x_battery_remove(struct i2c_client *client) { struct ds278x_info *info = i2c_get_clientdata(client); - power_supply_unregister(info->battery); cancel_delayed_work_sync(&info->bat_work); } @@ -415,8 +414,9 @@ static int ds278x_battery_probe(struct i2c_client *client) INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work); - info->battery = power_supply_register(&client->dev, - &info->battery_desc, &psy_cfg); + info->battery = devm_power_supply_register(&client->dev, + &info->battery_desc, + &psy_cfg); if (IS_ERR(info->battery)) { dev_err(&client->dev, "failed to register battery\n"); return PTR_ERR(info->battery); From patchwork Mon Dec 2 21:15:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 13891314 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (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 D24F31DF254; Mon, 2 Dec 2024 21:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174127; cv=none; b=hEsJrQ5loqBUvqf9iyJTmlzGnHW9Jm2ziZQvK5Pm3qpGWFTdPM9ZY6gkt0Von+yoPKp7v7DF6JeiKoBZCgl7gTQHTyGm+U/djf2IIGOTo5/gVqDFtvCyKAv4x/c/25FTh1v6p8/HPbgXcFtpffzm1euEYD5NZDebh9jhOhpsNV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733174127; c=relaxed/simple; bh=5xBRl6LYJX84sBYDQoMlNHxrwFZvRBjU54HJ4TDu9v0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iY2xEib41ddbV7FcH7KC8WnH5cmnGNcj3PGXrmCtynES1bomN8Q4TVoMRYZVJ6gVXCYW+EjKVSt9+yID3pHqK3pgQ8lqPboZdrvntDrRay1Q9G0poV4AsVBzSNYzhRSc+DNx0PB73EJL5MHkLeLBhW101rY2EOJKn2JbhuO67dY= 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=VaaKdBD0; arc=none smtp.client-ip=198.47.19.246 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="VaaKdBD0" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 4B2LFL7T1522484 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 2 Dec 2024 15:15:21 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1733174121; bh=n22cYySdwX9dZAn+uyVPdwYnc8ISC4OTsUIj22ELFlU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=VaaKdBD0Gw8VJmuXm2GzC4PF/mqKsqQzG+W1pK+j21Q5A4t0aAV/JyjciEm4W92j1 aMH5uGT95NsNdw2tAo//DqRGoPP/EQj1cnh1ozROcygDOuKp/HKX2I36n1j4jtrCE3 NPO96LbWZP+2Fv5Ne2QBwRvP7uofBfm+SqOgqHG0= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFLhe121625; Mon, 2 Dec 2024 15:15:21 -0600 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 2 Dec 2024 15:15:21 -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; Mon, 2 Dec 2024 15:15:21 -0600 Received: from fllvsmtp7.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4B2LFKgs099805; Mon, 2 Dec 2024 15:15:21 -0600 From: Andrew Davis To: Sebastian Reichel CC: , , Andrew Davis Subject: [PATCH 5/5] power: supply: ds2782: Use devm_delayed_work_autocancel() helper Date: Mon, 2 Dec 2024 15:15:19 -0600 Message-ID: <20241202211519.199635-5-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241202211519.199635-1-afd@ti.com> References: <20241202211519.199635-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Use the device lifecycle managed work init function. This helps prevent mistakes like canceling out of order in cleanup functions and forgetting to canceling on error paths. Note we move this to after the registering the power supply so that the cancel is called before unregistering. This was the last thing the .remove() function did, so remove that too. Signed-off-by: Andrew Davis --- drivers/power/supply/ds2782_battery.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c index ea687b9703314..cae95d35d3980 100644 --- a/drivers/power/supply/ds2782_battery.c +++ b/drivers/power/supply/ds2782_battery.c @@ -11,6 +11,7 @@ * UEvent sending added by Evgeny Romanov */ +#include #include #include #include @@ -310,13 +311,6 @@ static void ds278x_power_supply_init(struct power_supply_desc *battery) battery->external_power_changed = NULL; } -static void ds278x_battery_remove(struct i2c_client *client) -{ - struct ds278x_info *info = i2c_get_clientdata(client); - - cancel_delayed_work_sync(&info->bat_work); -} - #ifdef CONFIG_PM_SLEEP static int ds278x_suspend(struct device *dev) @@ -412,18 +406,19 @@ static int ds278x_battery_probe(struct i2c_client *client) info->capacity = 100; info->status = POWER_SUPPLY_STATUS_FULL; - INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work); - info->battery = devm_power_supply_register(&client->dev, &info->battery_desc, &psy_cfg); if (IS_ERR(info->battery)) { dev_err(&client->dev, "failed to register battery\n"); return PTR_ERR(info->battery); - } else { - schedule_delayed_work(&info->bat_work, DS278x_DELAY); } + ret = devm_delayed_work_autocancel(&client->dev, &info->bat_work, ds278x_bat_work); + if (ret) + return ret; + schedule_delayed_work(&info->bat_work, DS278x_DELAY); + return 0; } @@ -440,7 +435,6 @@ static struct i2c_driver ds278x_battery_driver = { .pm = &ds278x_battery_pm_ops, }, .probe = ds278x_battery_probe, - .remove = ds278x_battery_remove, .id_table = ds278x_id, }; module_i2c_driver(ds278x_battery_driver);