All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	Jassi Brar <jassisinghbrar@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>,
	Mikko Perttunen <mperttunen@nvidia.com>,
	Jon Hunter <jonathanh@nvidia.com>, Timo Alho <talho@nvidia.com>,
	Pekka Pessi <ppessi@nvidia.com>,
	Mika Liljeberg <mliljeberg@nvidia.com>,
	linux-tegra@vger.kernel.org, linux-serial@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: [PATCH v3 06/12] mailbox: tegra-hsp: use devm_kstrdup_const()
Date: Wed, 28 Nov 2018 10:54:15 +0100	[thread overview]
Message-ID: <20181128095421.20573-7-thierry.reding@gmail.com> (raw)
In-Reply-To: <20181128095421.20573-1-thierry.reding@gmail.com>

From: Bartosz Golaszewski <brgl@bgdev.pl>

Use devm_kstrdup_const() in the tegra-hsp driver. This mostly serves as
an example of how to use this new routine to shrink driver code.

Also use devm_kzalloc() instead of regular kzalloc() to shrink the
driver even more.

Doorbell objects are only removed in the driver's remove callback so
it's safe to convert all memory allocations to devres.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/mailbox/tegra-hsp.c | 36 ++++--------------------------------
 1 file changed, 4 insertions(+), 32 deletions(-)

diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c
index 07d1fbff3642..9628e52e2371 100644
--- a/drivers/mailbox/tegra-hsp.c
+++ b/drivers/mailbox/tegra-hsp.c
@@ -281,7 +281,7 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name,
 	unsigned int offset;
 	unsigned long flags;
 
-	db = kzalloc(sizeof(*db), GFP_KERNEL);
+	db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL);
 	if (!db)
 		return ERR_PTR(-ENOMEM);
 
@@ -291,7 +291,7 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name,
 	db->channel.regs = hsp->regs + offset;
 	db->channel.hsp = hsp;
 
-	db->name = kstrdup_const(name, GFP_KERNEL);
+	db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL);
 	db->master = master;
 	db->index = index;
 
@@ -302,13 +302,6 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name,
 	return &db->channel;
 }
 
-static void __tegra_hsp_doorbell_destroy(struct tegra_hsp_doorbell *db)
-{
-	list_del(&db->list);
-	kfree_const(db->name);
-	kfree(db);
-}
-
 static int tegra_hsp_doorbell_send_data(struct mbox_chan *chan, void *data)
 {
 	struct tegra_hsp_doorbell *db = chan->con_priv;
@@ -567,19 +560,6 @@ static struct mbox_chan *tegra_hsp_sm_xlate(struct mbox_controller *mbox,
 	return mb->channel.chan;
 }
 
-static void tegra_hsp_remove_doorbells(struct tegra_hsp *hsp)
-{
-	struct tegra_hsp_doorbell *db, *tmp;
-	unsigned long flags;
-
-	spin_lock_irqsave(&hsp->lock, flags);
-
-	list_for_each_entry_safe(db, tmp, &hsp->doorbells, list)
-		__tegra_hsp_doorbell_destroy(db);
-
-	spin_unlock_irqrestore(&hsp->lock, flags);
-}
-
 static int tegra_hsp_add_doorbells(struct tegra_hsp *hsp)
 {
 	const struct tegra_hsp_db_map *map = hsp->soc->map;
@@ -588,10 +568,8 @@ static int tegra_hsp_add_doorbells(struct tegra_hsp *hsp)
 	while (map->name) {
 		channel = tegra_hsp_doorbell_create(hsp, map->name,
 						    map->master, map->index);
-		if (IS_ERR(channel)) {
-			tegra_hsp_remove_doorbells(hsp);
+		if (IS_ERR(channel))
 			return PTR_ERR(channel);
-		}
 
 		map++;
 	}
@@ -747,7 +725,7 @@ static int tegra_hsp_probe(struct platform_device *pdev)
 	if (err < 0) {
 		dev_err(&pdev->dev, "failed to register doorbell mailbox: %d\n",
 			err);
-		goto remove_doorbells;
+		return err;
 	}
 
 	/* setup the shared mailbox controller */
@@ -804,9 +782,6 @@ static int tegra_hsp_probe(struct platform_device *pdev)
 	mbox_controller_unregister(&hsp->mbox_sm);
 unregister_mbox_db:
 	mbox_controller_unregister(&hsp->mbox_db);
-remove_doorbells:
-	if (hsp->doorbell_irq)
-		tegra_hsp_remove_doorbells(hsp);
 
 	return err;
 }
@@ -818,9 +793,6 @@ static int tegra_hsp_remove(struct platform_device *pdev)
 	mbox_controller_unregister(&hsp->mbox_sm);
 	mbox_controller_unregister(&hsp->mbox_db);
 
-	if (hsp->doorbell_irq)
-		tegra_hsp_remove_doorbells(hsp);
-
 	return 0;
 }
 
-- 
2.19.1

  parent reply	other threads:[~2018-11-28 20:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28  9:54 [PATCH v3 00/12] serial: Add Tegra Combined UART driver Thierry Reding
2018-11-28  9:54 ` [PATCH v3 01/12] mailbox: Support blocking transfers in atomic context Thierry Reding
2018-11-28  9:54 ` [PATCH v3 02/12] mailbox: Allow multiple controllers per device Thierry Reding
2018-11-28  9:54 ` [PATCH v3 03/12] dt-bindings: tegra186-hsp: Add shared mailboxes Thierry Reding
2018-11-28  9:54 ` [PATCH v3 04/12] mailbox: tegra-hsp: Add support for " Thierry Reding
2018-11-28  9:54 ` [PATCH v3 05/12] mailbox: tegra-hsp: Add suspend/resume support Thierry Reding
2018-11-28  9:54 ` Thierry Reding [this message]
2018-11-28  9:54 ` [PATCH v3 07/12] mailbox: tegra-hsp: Use device-managed registration API Thierry Reding
2018-11-28  9:54 ` [PATCH v3 08/12] dt-bindings: serial: Add bindings for nvidia,tegra194-tcu Thierry Reding
2018-11-28  9:54 ` [PATCH v3 09/12] serial: Add Tegra Combined UART driver Thierry Reding
2018-11-28  9:54 ` [PATCH v3 10/12] arm64: tegra: Add nodes for TCU on Tegra194 Thierry Reding
2018-11-28  9:54 ` [PATCH v3 11/12] arm64: tegra: Mark TCU as primary serial port on Tegra194 P2888 Thierry Reding
2018-11-28  9:54 ` [PATCH v3 12/12] arm64: defconfig: Enable Tegra TCU Thierry Reding
2018-12-05 16:15 ` [PATCH v3 00/12] serial: Add Tegra Combined UART driver Thierry Reding
2018-12-22  5:13 ` Jassi Brar

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=20181128095421.20573-7-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=jslaby@suse.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mliljeberg@nvidia.com \
    --cc=mperttunen@nvidia.com \
    --cc=ppessi@nvidia.com \
    --cc=talho@nvidia.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.