LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Markus Elfring <Markus.Elfring@web.de>,
	linuxppc-dev@lists.ozlabs.org,
	Jani Nikula <jani.nikula@intel.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Naveen N Rao <naveen@kernel.org>,
	Nicholas Piggin <npiggin@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Subject: Re: [PATCH] powermac: Use of_property_match_string() in pmac_has_backlight_type()
Date: Sun, 13 Oct 2024 16:41:08 +0300	[thread overview]
Message-ID: <e50907a9-6df7-4cbf-97a6-47acd5d8ce01@stanley.mountain> (raw)
In-Reply-To: <c629e544-f768-4063-bd2c-f72382bdf69b@csgroup.eu>

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



  reply	other threads:[~2024-10-13 13:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02 20:02 [PATCH] powermac: Call of_node_put(bk_node) only once in pmac_has_backlight_type() Markus Elfring
2024-10-02 20:43 ` Christophe Leroy
2024-10-03  5:56   ` Dan Carpenter
2024-10-03  6:53     ` Krzysztof Kozlowski
2024-10-07  7:15     ` Markus Elfring
2024-10-09  4:48   ` [PATCH] " Michael Ellerman
2024-10-11 16:18   ` [PATCH] powermac: Use of_property_match_string() " Markus Elfring
2024-10-11 16:25     ` Christophe Leroy
2024-10-13 13:41       ` Dan Carpenter [this message]
2024-11-17 12:09     ` Michael Ellerman

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=e50907a9-6df7-4cbf-97a6-47acd5d8ce01@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=Markus.Elfring@web.de \
    --cc=christophe.leroy@csgroup.eu \
    --cc=jani.nikula@intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=naveen@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=paulus@samba.org \
    --cc=sfr@canb.auug.org.au \
    --cc=tzimmermann@suse.de \
    /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