mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Liang He" <windhl@126.com>
To: "Greg KH" <gregkh@linuxfoundation.org>
Cc: broonie@kernel.org, ckeepax@opensource.cirrus.com,
	michal.simek@xilinx.com, abhyuday.godhasara@xilinx.com,
	simont@opensource.cirrus.com, ronak.jain@xilinx.com,
	peng.fan@nxp.com, linux-kernel@vger.kernel.org
Subject: Re:Re: Re: [PATCH] firmware: Hold a reference for of_find_compatible_node()
Date: Mon, 27 Jun 2022 23:14:50 +0800 (CST)	[thread overview]
Message-ID: <1bed06e5.43da.181a5bac7e5.Coremail.windhl@126.com> (raw)
In-Reply-To: <YrnG3ymy0dg/VPQs@kroah.com>



At 2022-06-27 23:03:59, "Greg KH" <gregkh@linuxfoundation.org> wrote:
>On Mon, Jun 27, 2022 at 10:51:38PM +0800, Liang He wrote:
>> 
>> 
>> At 2022-06-27 22:09:43, "Greg KH" <gregkh@linuxfoundation.org> wrote:
>> >On Tue, Jun 21, 2022 at 11:26:25AM +0800, Liang He wrote:
>> >> In of_register_trusted_foundations(), we need to hold the reference
>> >> returned by of_find_compatible_node() and then use it to call
>> >> of_node_put() for refcount balance.
>> >> 
>> >> Signed-off-by: Liang He <windhl@126.com>
>> >> ---
>> >>  include/linux/firmware/trusted_foundations.h | 8 ++++++--
>> >>  1 file changed, 6 insertions(+), 2 deletions(-)
>> >> 
>> >> diff --git a/include/linux/firmware/trusted_foundations.h b/include/linux/firmware/trusted_foundations.h
>> >> index be5984bda592..399471c2f1c7 100644
>> >> --- a/include/linux/firmware/trusted_foundations.h
>> >> +++ b/include/linux/firmware/trusted_foundations.h
>> >> @@ -71,12 +71,16 @@ static inline void register_trusted_foundations(
>> >>  
>> >>  static inline void of_register_trusted_foundations(void)
>> >>  {
>> >> +	struct device_node *np = of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
>> >> +
>> >> +	of_node_put(np);
>> >> +	if (!np)
>> >
>> >While this is technically correct, you are now checking to see if this
>> >points to a memory location that you no longer know what it really
>> >belongs to.  C will let you do this, but it might be nicer to fix it up
>> >properly so it doesn't look like this.
>> >
>> >thanks,
>> >
>> >greg k-h
>> 
>> Hi,Greg KH,
>> 
>> Thanks very much for your effort to review my patch.
>> 
>> In fact, I have reported a commit for this kind of 'check-after-put' coding style:
>> https://lore.kernel.org/all/20220617112636.4041671-1-windhl@126.com/
>> 
>> But I have been told to keep such style and I think the explanation is also reasonable.
>
>It's not very reasonable if you talk to C compiler authors.  They can do
>crazy things with dereferenced memory locations, including optimizing
>them away entirely as they now "know" that this does not point to any
>valid memory so it's an undefined thing that the compiler is being asked
>to do.
>
>> So when I make this patch, I am indeed confused what I should write.
>> 
>> Finally, I think it is better to be consistent with current coding style so
>> I chose this 'check-after-put' style.
>> 
>> But if you think it is better to use a normal order, i.e., check-then-put,
>> I am, of cause, very happy to send a new patch for this bug and I will
>> also keep to use this coding style in future.
>
>check and then put please.  That prevents you from having to fix up this
>type of thing in a few years when the compilers all start to blow up on
>it.
>
>thanks,
>
>greg k-h

OK, Greg KH,

I am very happy to hear this and I will send 'check-and-put' patch tomorrow.

Thanks very much.

Liang

      reply	other threads:[~2022-06-27 15:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  3:26 Liang He
2022-06-27 14:09 ` Greg KH
2022-06-27 14:51   ` Liang He
2022-06-27 15:03     ` Greg KH
2022-06-27 15:14       ` Liang He [this message]

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=1bed06e5.43da.181a5bac7e5.Coremail.windhl@126.com \
    --to=windhl@126.com \
    --cc=abhyuday.godhasara@xilinx.com \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=peng.fan@nxp.com \
    --cc=ronak.jain@xilinx.com \
    --cc=simont@opensource.cirrus.com \
    /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

all inboxes | Powered by JetHome®