public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: Biju Das <biju.das.jz@bp.renesas.com>
Cc: "linux-renesas-soc@vger.kernel.org" 
	<linux-renesas-soc@vger.kernel.org>,
	Chris Brandt <Chris.Brandt@renesas.com>,
	Andi Shyti <andi.shyti@kernel.org>,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 5/5] i2c: riic: avoid potential division by zero
Date: Thu, 7 Sep 2023 14:08:52 +0200	[thread overview]
Message-ID: <ZPm9VBi+nLrSaUl6@ninjato> (raw)
In-Reply-To: <OS0PR01MB59221A1F4614F30669F3448D86EEA@OS0PR01MB5922.jpnprd01.prod.outlook.com>

[-- Attachment #1: Type: text/plain, Size: 377 bytes --]


> > -	total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz);
> > +	total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz ?: 1);
> 
> Not sure clamping function min_t/min(t->bus_freq_hz, 1)
> Or ternary condition is good in this case for avoiding potential division by 0?

Both work. I chose the ternary because I believe it involves less
computation and a tad tighter syntax.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2023-09-07 16:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06 20:00 [PATCH 0/5] i2c: clock calculation cleanups for Renesas devices Wolfram Sang
2023-09-06 20:00 ` [PATCH 1/5] i2c: rcar: avoid non-standard use of goto Wolfram Sang
2023-09-08 15:03   ` Geert Uytterhoeven
2023-09-06 20:00 ` [PATCH 2/5] i2c: rcar: properly format a debug output Wolfram Sang
2023-09-08 15:04   ` Geert Uytterhoeven
2023-09-06 20:00 ` [PATCH 3/5] i2c: rcar: calculate divider instead of brute-forcing it Wolfram Sang
2023-09-19  8:33   ` Geert Uytterhoeven
2023-09-06 20:00 ` [PATCH 4/5] i2c: rcar: remove open coded DIV_ROUND_CLOSEST Wolfram Sang
2023-09-08 15:06   ` Geert Uytterhoeven
2023-09-06 20:00 ` [PATCH 5/5] i2c: riic: avoid potential division by zero Wolfram Sang
2023-09-07  6:42   ` Biju Das
2023-09-07  6:44     ` Biju Das
2023-09-07 12:08     ` Wolfram Sang [this message]
2023-09-08 15:09   ` Geert Uytterhoeven
2023-09-19  9:12 ` [PATCH 0/5] i2c: clock calculation cleanups for Renesas devices Wolfram Sang

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=ZPm9VBi+nLrSaUl6@ninjato \
    --to=wsa+renesas@sang-engineering.com \
    --cc=Chris.Brandt@renesas.com \
    --cc=andi.shyti@kernel.org \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.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