mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/7] ARM: tx28: use cdev_open_by_name()
Date: Thu, 16 May 2024 09:08:17 +0200	[thread overview]
Message-ID: <20240516070822.2746845-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240516070822.2746845-1-s.hauer@pengutronix.de>

cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/karo-tx28/tx28-stk5.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boards/karo-tx28/tx28-stk5.c b/arch/arm/boards/karo-tx28/tx28-stk5.c
index d1fd526c00..01a14a33a3 100644
--- a/arch/arm/boards/karo-tx28/tx28-stk5.c
+++ b/arch/arm/boards/karo-tx28/tx28-stk5.c
@@ -310,20 +310,21 @@ static const uint32_t tx28_starterkit_pad_setup[] = {
  */
 static int register_persistent_environment(void)
 {
-	struct cdev *cdev;
+	struct cdev *cdev, *env;
 
 	/*
 	 * The TX28 STK5 has only one usable MCI card socket.
 	 * So, we expect its name as "disk0".
 	 */
-	cdev = cdev_by_name("disk0");
+	cdev = cdev_open_by_name("disk0", O_RDONLY);
 	if (cdev == NULL) {
 		pr_err("No MCI card preset\n");
 		return -ENODEV;
 	}
+	cdev_close(cdev);
 
 	/* MCI card is present, also a usable partition on it? */
-	cdev = cdev_by_name("disk0.1");
+	cdev = cdev_open_by_name("disk0.1", O_RDONLY);
 	if (cdev == NULL) {
 		pr_err("No second partition available\n");
 		pr_info("Please create at least a second partition with"
@@ -332,9 +333,11 @@ static int register_persistent_environment(void)
 	}
 
 	/* use the full partition as our persistent environment storage */
-	cdev = devfs_add_partition("disk0.1", 0, cdev->size,
+	env = devfs_add_partition("disk0.1", 0, cdev->size,
 					DEVFS_PARTITION_FIXED, "env0");
-	return PTR_ERR_OR_ZERO(cdev);
+	cdev_close(cdev);
+
+	return PTR_ERR_OR_ZERO(env);
 }
 
 static void tx28_get_ethaddr(void)
-- 
2.39.2




  parent reply	other threads:[~2024-05-16  7:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16  7:08 [PATCH 0/7] replace cdev_by_name() with cdev_open_by_name() Sascha Hauer
2024-05-16  7:08 ` [PATCH 1/7] ARM: Freescale i.MX23 evk: use cdev_open_by_name() Sascha Hauer
2024-05-16  7:08 ` Sascha Hauer [this message]
2024-05-16  7:08 ` [PATCH 3/7] ARM: omap: " Sascha Hauer
2024-05-16  7:08 ` [PATCH 4/7] ARM: Rockchip: " Sascha Hauer
2024-05-16  7:08 ` [PATCH 5/7] commands: devlookup: " Sascha Hauer
2024-05-16  7:08 ` [PATCH 6/7] commands: findmnt: " Sascha Hauer
2024-05-16  7:08 ` [PATCH 7/7] bootm: " Sascha Hauer
2024-05-16 14:43 ` [PATCH 0/7] replace cdev_by_name() with cdev_open_by_name() Marco Felsch
2024-05-16 15:01   ` Sascha Hauer
2024-05-21  6:17 ` Sascha Hauer

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=20240516070822.2746845-3-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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