Skip to content

Commit a93b873

Browse files
Laurent Pincharttomba
authored andcommitted
drm: rcar-du: Use __free() to simplify device_node handling
Replace manual of_node_put() calls with __free(). This simplifies error handling code and makes it less bug-prone. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Link: https://patch.msgid.link/20260323164526.2292491-4-laurent.pinchart+renesas@ideasonboard.com Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
1 parent 0f6f28c commit a93b873

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <drm/drm_probe_helper.h>
2020
#include <drm/drm_vblank.h>
2121

22+
#include <linux/cleanup.h>
2223
#include <linux/device.h>
2324
#include <linux/dma-buf.h>
2425
#include <linux/of.h>
@@ -573,7 +574,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
573574
enum rcar_du_output output,
574575
struct of_endpoint *ep)
575576
{
576-
struct device_node *entity;
577+
struct device_node *entity __free(device_node) = NULL;
577578
int ret;
578579

579580
/* Locate the connected entity and initialize the encoder. */
@@ -588,7 +589,6 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
588589
dev_dbg(rcdu->dev,
589590
"connected entity %pOF is disabled, skipping\n",
590591
entity);
591-
of_node_put(entity);
592592
return -ENODEV;
593593
}
594594

@@ -598,15 +598,13 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
598598
"failed to initialize encoder %pOF on output %s (%d), skipping\n",
599599
entity, rcar_du_output_name(output), ret);
600600

601-
of_node_put(entity);
602-
603601
return ret;
604602
}
605603

606604
static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
607605
{
606+
struct device_node *ep_node __free(device_node) = NULL;
608607
struct device_node *np = rcdu->dev->of_node;
609-
struct device_node *ep_node;
610608
unsigned int num_encoders = 0;
611609

612610
/*
@@ -620,10 +618,8 @@ static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
620618
int ret;
621619

622620
ret = of_graph_parse_endpoint(ep_node, &ep);
623-
if (ret < 0) {
624-
of_node_put(ep_node);
621+
if (ret < 0)
625622
return ret;
626-
}
627623

628624
/* Find the output route corresponding to the port number. */
629625
for (i = 0; i < RCAR_DU_OUTPUT_MAX; ++i) {
@@ -644,10 +640,8 @@ static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
644640
/* Process the output pipeline. */
645641
ret = rcar_du_encoders_init_one(rcdu, output, &ep);
646642
if (ret < 0) {
647-
if (ret == -EPROBE_DEFER) {
648-
of_node_put(ep_node);
643+
if (ret == -EPROBE_DEFER)
649644
return ret;
650-
}
651645

652646
continue;
653647
}
@@ -775,9 +769,9 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
775769
}
776770

777771
for (i = 0; i < cells; ++i) {
772+
struct device_node *cmm __free(device_node) = NULL;
778773
struct platform_device *pdev;
779774
struct device_link *link;
780-
struct device_node *cmm;
781775
int ret;
782776

783777
cmm = of_parse_phandle(np, "renesas,cmms", i);
@@ -787,21 +781,16 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
787781
return -EINVAL;
788782
}
789783

790-
if (!of_device_is_available(cmm)) {
784+
if (!of_device_is_available(cmm))
791785
/* It's fine to have a phandle to a non-enabled CMM. */
792-
of_node_put(cmm);
793786
continue;
794-
}
795787

796788
pdev = of_find_device_by_node(cmm);
797789
if (!pdev) {
798790
dev_err(rcdu->dev, "No device found for CMM%u\n", i);
799-
of_node_put(cmm);
800791
return -EINVAL;
801792
}
802793

803-
of_node_put(cmm);
804-
805794
/*
806795
* -ENODEV is used to report that the CMM config option is
807796
* disabled: return 0 and let the DU continue probing.

0 commit comments

Comments
 (0)