Re: [PATCH] powermac: Use of_property_match_string() in pmac_has_backlight_type()
From: Dan Carpenter
Date: Sun Oct 13 2024 - 09:41:23 EST
On Fri, Oct 11, 2024 at 06:25:45PM +0200, Christophe Leroy wrote:
> > diff --git a/arch/powerpc/platforms/powermac/backlight.c b/arch/powerpc/platforms/powermac/backlight.c
> > index 12bc01353bd3..79741370c40c 100644
> > --- a/arch/powerpc/platforms/powermac/backlight.c
> > +++ b/arch/powerpc/platforms/powermac/backlight.c
> > @@ -57,18 +57,10 @@ struct backlight_device *pmac_backlight;
> > int pmac_has_backlight_type(const char *type)
> > {
> > struct device_node* bk_node = of_find_node_by_name(NULL, "backlight");
> > + int i = of_property_match_string(bk_node, "backlight-control", type);
> >
> > - if (bk_node) {
> > - const char *prop = of_get_property(bk_node,
> > - "backlight-control", NULL);
> > - if (prop && strncmp(prop, type, strlen(type)) == 0) {
> > - of_node_put(bk_node);
> > - return 1;
> > - }
> > - of_node_put(bk_node);
> > - }
> > -
> > - return 0;
> > + of_node_put(bk_node);
> > + return i >= 0;
>
> Could have been:
>
> return !IS_ERR_VALUE(i);
>
IS_ERR_VALUE() macro should only be used when you're dealing with memory
addresses. What I mean is there places in mm/ where we pass addresses as
unsigned long values instead of pointers. For example, get_unmapped_area()
returns unsigned long. The IS_ERR_VALUE() macro is necessary for that.
For regular error codes, we can just check for negatives. we don't have do
anything fancy.
Of course, you can find counter examples, like msm_iommu_attach_dev() or
st_fdma_of_xlate(). <small joke>But in those cases, it's done to deliberately
to ensure that the code will never accidentally get built on 64bit systems.
</small joke>
regards,
dan carpenter