[PATCH 4/7] ARM: Rockchip: use cdev_open_by_name()

Sascha Hauer s.hauer at pengutronix.de
Thu May 16 00:08:19 PDT 2024


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 at pengutronix.de>
---
 arch/arm/mach-rockchip/bbu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-rockchip/bbu.c b/arch/arm/mach-rockchip/bbu.c
index f15b32937c..7715540863 100644
--- a/arch/arm/mach-rockchip/bbu.c
+++ b/arch/arm/mach-rockchip/bbu.c
@@ -43,6 +43,7 @@ static int rockchip_bbu_mmc_handler(struct bbu_handler *handler,
 	int ret, fd, wr0, wr1;
 	loff_t space;
 	const char *cdevname;
+	struct cdev *cdev;
 
 	filetype = file_detect_type(data->image, data->len);
 	if (filetype != filetype_rockchip_rkns_image) {
@@ -60,7 +61,12 @@ static int rockchip_bbu_mmc_handler(struct bbu_handler *handler,
 	if (ret)
 		return ret;
 
-	space = cdev_unallocated_space(cdev_by_name(cdevname));
+	cdev = cdev_open_by_name(cdevname, O_RDONLY);
+	if (!cdev)
+		return -ENOENT;
+
+	space = cdev_unallocated_space(cdev);
+	cdev_close(cdev);
 
 	if (space < IMG_OFFSET_0 + data->len) {
 		if (!bbu_force(data, "Unallocated space on %s (%lld) is too small for one image\n",
-- 
2.39.2




More information about the barebox mailing list