public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Hanna Hawa <hhhawa@amazon.com>
Cc: jarkko.nikula@linux.intel.com, mika.westerberg@linux.intel.com,
	jsd@semihalf.com, linux-i2c@vger.kernel.org,
	linux-kernel@vger.kernel.org, dwmw@amazon.co.uk, benh@amazon.com,
	ronenk@amazon.com, talel@amazon.com, jonnyc@amazon.com,
	hanochu@amazon.com, farbere@amazon.com, itamark@amazon.com,
	lareine@amazon.com
Subject: Re: [PATCH v2 1/1] i2c: designware: use u64 for clock freq to avoid u32 multiplication overflow
Date: Wed, 14 Dec 2022 18:12:12 +0200	[thread overview]
Message-ID: <Y5n13HLzvMIy3RVh@smile.fi.intel.com> (raw)
In-Reply-To: <20221214154117.65714-1-hhhawa@amazon.com>

On Wed, Dec 14, 2022 at 03:41:17PM +0000, Hanna Hawa wrote:
> From: Lareine Khawaly <lareine@amazon.com>
> 
> In functions i2c_dw_scl_lcnt() and i2c_dw_scl_hcnt() may have overflow
> by depending on the values of the given parameters including the ic_clk.
> For example in our use case where ic_clk is larger than one million,
> multiplication of ic_clk * 4700 will result in 32 bit overflow.
> 
> Make the ic_clk to be u64 parameter to avoid the overflow.

Below my comment, after addressing it,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Change Log v1->v2:
> - Update commit message and add fix tag.

Wrong location of the changelog...

> Fixes: 2373f6b9744d ("i2c-designware: split of i2c-designware.c into core and bus specific parts")
> Signed-off-by: Lareine Khawaly <lareine@amazon.com>
> Signed-off-by: Hanna Hawa <hhhawa@amazon.com>
> ---

...should be somewhere here.

>  drivers/i2c/busses/i2c-designware-common.c | 4 ++--
>  drivers/i2c/busses/i2c-designware-core.h   | 4 ++--
>  drivers/i2c/busses/i2c-designware-master.c | 2 +-
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
> index c023b691441e..61a6b7bb8935 100644
> --- a/drivers/i2c/busses/i2c-designware-common.c
> +++ b/drivers/i2c/busses/i2c-designware-common.c
> @@ -332,7 +332,7 @@ void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev)
>  }
>  EXPORT_SYMBOL_GPL(i2c_dw_adjust_bus_speed);
>  
> -u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
> +u32 i2c_dw_scl_hcnt(u64 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
>  {
>  	/*
>  	 * DesignWare I2C core doesn't seem to have solid strategy to meet
> @@ -370,7 +370,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
>  		return DIV_ROUND_CLOSEST(ic_clk * (tSYMBOL + tf), MICRO) - 3 + offset;
>  }
>  
> -u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
> +u32 i2c_dw_scl_lcnt(u64 ic_clk, u32 tLOW, u32 tf, int offset)
>  {
>  	/*
>  	 * Conditional expression:
> diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
> index 4d3a3b464ecd..aaba6f9977b6 100644
> --- a/drivers/i2c/busses/i2c-designware-core.h
> +++ b/drivers/i2c/busses/i2c-designware-core.h
> @@ -319,8 +319,8 @@ struct i2c_dw_semaphore_callbacks {
>  };
>  
>  int i2c_dw_init_regmap(struct dw_i2c_dev *dev);
> -u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset);
> -u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset);
> +u32 i2c_dw_scl_hcnt(u64 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset);
> +u32 i2c_dw_scl_lcnt(u64 ic_clk, u32 tLOW, u32 tf, int offset);
>  int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev);
>  unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev);
>  int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare);
> diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
> index 16a4cd68567c..bfa2b37fb3f7 100644
> --- a/drivers/i2c/busses/i2c-designware-master.c
> +++ b/drivers/i2c/busses/i2c-designware-master.c
> @@ -44,7 +44,7 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev)
>  	u32 sda_falling_time, scl_falling_time;
>  	struct i2c_timings *t = &dev->timings;
>  	const char *fp_str = "";
> -	u32 ic_clk;
> +	u64 ic_clk;
>  	int ret;
>  
>  	ret = i2c_dw_acquire_lock(dev);
> -- 
> 2.38.1
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2022-12-14 16:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 15:41 [PATCH v2 1/1] i2c: designware: use u64 for clock freq to avoid u32 multiplication overflow Hanna Hawa
2022-12-14 16:12 ` Andy Shevchenko [this message]
2022-12-14 16:18   ` Andy Shevchenko
2022-12-14 16:19     ` Andy Shevchenko
2022-12-15  0:17 ` kernel test robot
2022-12-15  3:29 ` kernel test robot

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=Y5n13HLzvMIy3RVh@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=benh@amazon.com \
    --cc=dwmw@amazon.co.uk \
    --cc=farbere@amazon.com \
    --cc=hanochu@amazon.com \
    --cc=hhhawa@amazon.com \
    --cc=itamark@amazon.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jonnyc@amazon.com \
    --cc=jsd@semihalf.com \
    --cc=lareine@amazon.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=ronenk@amazon.com \
    --cc=talel@amazon.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