mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH master 1/2] clk: harden NULL handling in clk_hw_to_clk/clk_to_clk_hw
Date: Tue, 8 Mar 2022 09:19:01 +0100	[thread overview]
Message-ID: <20220308081901.GF405@pengutronix.de> (raw)
In-Reply-To: <20220307170106.3937198-1-a.fatoum@pengutronix.de>

On Mon, Mar 07, 2022 at 06:01:05PM +0100, Ahmad Fatoum wrote:
> As clk_hw::clk is the first member and there may no be leading padding,
> clk_hw_to_clk(NULL) == clk_to_clk_hw(NULL) == NULL. This would break if
> we moved struct clk around, so make this more robust by using
> IS_ERR_OR_NULL. No functional change.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/linux/clk.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/clk.h b/include/linux/clk.h
> index c0e998e54ae6..7fd835c35e51 100644
> --- a/include/linux/clk.h
> +++ b/include/linux/clk.h
> @@ -433,12 +433,14 @@ struct clk_hw {
>  
>  static inline struct clk *clk_hw_to_clk(const struct clk_hw *hw)
>  {
> -	return IS_ERR(hw) ? ERR_CAST(hw) : (struct clk *)&hw->clk;
> +	return IS_ERR_OR_NULL(hw) ? ERR_CAST(hw)
> +				  : (struct clk *)&hw->clk;
>  }

This one doesn't apply to master, but on next. Applied it there instead.

Sascha

>  
>  static inline struct clk_hw *clk_to_clk_hw(const struct clk *clk)
>  {
> -	return IS_ERR(clk) ? ERR_CAST(clk) : (struct clk_hw *)container_of(clk, struct clk_hw, clk);
> +	return IS_ERR_OR_NULL(clk) ? ERR_CAST(clk)
> +				   : (struct clk_hw *)container_of(clk, struct clk_hw, clk);
>  }
>  
>  struct clk_div_table {
> -- 
> 2.30.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


      parent reply	other threads:[~2022-03-08  8:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 17:01 Ahmad Fatoum
2022-03-07 17:01 ` [PATCH master 2/2] clk: composite: fix possible NULL pointer dereference Ahmad Fatoum
2022-03-08  8:19 ` Sascha Hauer [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=20220308081901.GF405@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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