linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH 8/8] rtc: shrink devm_rtc_allocate_device()
Date: Mon,  9 Nov 2020 17:34:09 +0100	[thread overview]
Message-ID: <20201109163409.24301-9-brgl@bgdev.pl> (raw)
In-Reply-To: <20201109163409.24301-1-brgl@bgdev.pl>

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We don't need to use devres_alloc() & devres_add() manually if all we
want to manage is a single pointer. We can shrink the code by using
devm_add_action_or_reset() instead. The number of allocations stays
the same.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/rtc/class.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index b8a34ee039ad..a1b3711aaf01 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -337,48 +337,37 @@ static void devm_rtc_unregister_device(void *data)
 	put_device(&rtc->dev);
 }
 
-static void devm_rtc_release_device(struct device *dev, void *res)
+static void devm_rtc_release_device(void *res)
 {
-	struct rtc_device *rtc = *(struct rtc_device **)res;
+	struct rtc_device *rtc = res;
 
 	put_device(&rtc->dev);
 }
 
 struct rtc_device *devm_rtc_allocate_device(struct device *dev)
 {
-	struct rtc_device **ptr, *rtc;
+	struct rtc_device *rtc;
 	int id, err;
 
 	id = rtc_device_get_id(dev);
 	if (id < 0)
 		return ERR_PTR(id);
 
-	ptr = devres_alloc(devm_rtc_release_device, sizeof(*ptr), GFP_KERNEL);
-	if (!ptr) {
-		err = -ENOMEM;
-		goto exit_ida;
-	}
-
 	rtc = rtc_allocate_device();
 	if (!rtc) {
-		err = -ENOMEM;
-		goto exit_devres;
+		ida_simple_remove(&rtc_ida, id);
+		return ERR_PTR(-ENOMEM);
 	}
 
-	*ptr = rtc;
-	devres_add(dev, ptr);
-
 	rtc->id = id;
 	rtc->dev.parent = dev;
 	dev_set_name(&rtc->dev, "rtc%d", id);
 
-	return rtc;
+	err = devm_add_action_or_reset(dev, devm_rtc_release_device, rtc);
+	if (err)
+		return ERR_PTR(err);
 
-exit_devres:
-	devres_free(ptr);
-exit_ida:
-	ida_simple_remove(&rtc_ida, id);
-	return ERR_PTR(err);
+	return rtc;
 }
 EXPORT_SYMBOL_GPL(devm_rtc_allocate_device);
 
-- 
2.29.1


  parent reply	other threads:[~2020-11-09 16:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-09 16:34 [PATCH 0/8] rtc: rework resource management Bartosz Golaszewski
2020-11-09 16:34 ` [PATCH 1/8] rtc: omap: use devm_pinctrl_register() Bartosz Golaszewski
2020-11-09 16:34 ` [PATCH 2/8] Revert "rtc: sc27xx: Always read normal alarm when registering RTC device" Bartosz Golaszewski
2020-11-17 21:23   ` Alexandre Belloni
2020-11-09 16:34 ` [PATCH 3/8] Documentation: list RTC devres helpers in devres.rst Bartosz Golaszewski
2020-11-09 16:34 ` [PATCH 4/8] rtc: nvmem: remove nvram ABI Bartosz Golaszewski
2020-11-09 16:34 ` [PATCH 5/8] rtc: add devm_ prefix to rtc_nvmem_register() Bartosz Golaszewski
2020-11-09 16:34 ` [PATCH 6/8] rtc: nvmem: emit an error message when nvmem registration fails Bartosz Golaszewski
2020-11-09 16:34 ` [PATCH 7/8] rtc: rework rtc_register_device() resource management Bartosz Golaszewski
2020-11-17 21:35   ` Alexandre Belloni
2020-11-18  8:13     ` Bartosz Golaszewski
     [not found]   ` <CAF2Aj3inp8=dn9xuc8f3uJbL+m5LH7W3BDoOeZyiiOupmbfgOw@mail.gmail.com>
2020-11-27  9:23     ` Bartosz Golaszewski
2020-11-27 13:22       ` Lee Jones
2020-11-09 16:34 ` Bartosz Golaszewski [this message]
2020-11-17 22:57 ` [PATCH 0/8] rtc: rework " Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201109163409.24301-9-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).