From: Alex Elder <elder@ieee.org>
To: Javi Merino <javi.merino@arm.com>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"intel-gfx@lists.freedesktop.org"
<intel-gfx@lists.freedesktop.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Antti Palosaari <crope@iki.fi>,
Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Subject: Re: [PATCH 4/4] media: cxd2820r: use DIV_ROUND_CLOSEST_ULL()
Date: Fri, 20 Mar 2015 14:46:06 -0500 [thread overview]
Message-ID: <550C78FE.3060908@ieee.org> (raw)
In-Reply-To: <20150320172721.GA31927@e104805>
On 03/20/2015 12:27 PM, Javi Merino wrote:
> On Fri, Mar 20, 2015 at 01:51:36PM +0000, Alex Elder wrote:
>> On 03/20/2015 06:14 AM, Javi Merino wrote:
>>> Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
>>> implementation and use the kernel one.
>>>
>>> Cc: Antti Palosaari <crope@iki.fi>
>>> Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>>> Signed-off-by: Javi Merino <javi.merino@arm.com>
>>> ---
>>> I've only compile-tested it, I don't have the hardware to run it.
>>>
>>> drivers/media/dvb-frontends/cxd2820r_c.c | 2 +-
>>> drivers/media/dvb-frontends/cxd2820r_core.c | 6 ------
>>> drivers/media/dvb-frontends/cxd2820r_priv.h | 2 --
>>> drivers/media/dvb-frontends/cxd2820r_t.c | 2 +-
>>> drivers/media/dvb-frontends/cxd2820r_t2.c | 2 +-
>>> 5 files changed, 3 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c b/drivers/media/dvb-frontends/cxd2820r_c.c
>>> index 149fdca3fb44..72b0e2db3aab 100644
>>> --- a/drivers/media/dvb-frontends/cxd2820r_c.c
>>> +++ b/drivers/media/dvb-frontends/cxd2820r_c.c
>>> @@ -79,7 +79,7 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
>>>
>>> num = if_freq / 1000; /* Hz => kHz */
>>> num *= 0x4000;
>>> - if_ctl = 0x4000 - cxd2820r_div_u64_round_closest(num, 41000);
>>> + if_ctl = 0x4000 - DIV_ROUND_CLOSEST_ULL(num, 41000);
>>> buf[0] = (if_ctl >> 8) & 0x3f;
>>> buf[1] = (if_ctl >> 0) & 0xff;
>>>
>>> diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
>>> index 422e84bbb008..490e090048ef 100644
>>> --- a/drivers/media/dvb-frontends/cxd2820r_core.c
>>> +++ b/drivers/media/dvb-frontends/cxd2820r_core.c
>>> @@ -244,12 +244,6 @@ error:
>>> return ret;
>>> }
>>>
>>> -/* 64 bit div with round closest, like DIV_ROUND_CLOSEST but 64 bit */
>>> -u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor)
>>> -{
>>> - return div_u64(dividend + (divisor / 2), divisor);
>>> -}
>>
>> Technically, I'd say this has a bug, because the result
>> needs to be 64 bits wide or your results might be much
>> different from what might be desired.
>>
>> Practically though, I'm pretty sure all callers provide
>> values that ensure the result is valid.
>
> All the callers are substituted in this patch so we can make sure that
> they are all correct.
>
>> I only call attention because this patch changes the return
>> type of the function that gets called to do the calculation.
>
> I'm not sure I follow. Do you mean that this:
>
> if_ctl = 0x4000 - DIV_ROUND_CLOSEST_ULL(num, 41000);
>
> Should actually be:
>
> if_ctl = 0x4000 - (u32)DIV_ROUND_CLOSEST_ULL(num, 41000);
I'm merely stating that your change includes changing the
type of the value returned (cxd2820r_div_u64_round_closest()
returns u32, DIV_ROUND_CLOSEST_ULL() returns U64). So
in that respect, your patch is not completely trivial.
That said, as you point out (and I also did a quick check)
it does not seem to be an issue here.
The bug (if you call it that) existed before your patch, and
I am not suggesting you change anything. Just hoping for
a verification that the different return type does not
lead to any problems. I'm convinced.
-Alex
> ?
>
> if_ctl is a u16 so I don't think you gain anything by doing that.
>
>>> -
>>> static int cxd2820r_set_frontend(struct dvb_frontend *fe)
>>> {
>>> struct cxd2820r_priv *priv = fe->demodulator_priv;
>>> diff --git a/drivers/media/dvb-frontends/cxd2820r_priv.h b/drivers/media/dvb-frontends/cxd2820r_priv.h
>>> index 7ff5f60c83e1..4b428959b16e 100644
>>> --- a/drivers/media/dvb-frontends/cxd2820r_priv.h
>>> +++ b/drivers/media/dvb-frontends/cxd2820r_priv.h
>>> @@ -64,8 +64,6 @@ int cxd2820r_wr_reg_mask(struct cxd2820r_priv *priv, u32 reg, u8 val,
>>> int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
>>> int len);
>>>
>>> -u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor);
>>> -
>>> int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
>>> int len);
>>>
>>> diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c b/drivers/media/dvb-frontends/cxd2820r_t.c
>>> index 51401d036530..008cb2ac8480 100644
>>> --- a/drivers/media/dvb-frontends/cxd2820r_t.c
>>> +++ b/drivers/media/dvb-frontends/cxd2820r_t.c
>>> @@ -103,7 +103,7 @@ int cxd2820r_set_frontend_t(struct dvb_frontend *fe)
>>>
>>> num = if_freq / 1000; /* Hz => kHz */
>>> num *= 0x1000000;
>>> - if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
>>> + if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000);
>
> if_ctl is a u32, so you get the same behavior that you were getting
> before: the downcasting of u64 to u32 happened in
> cxd2820r_div_u64_round_closest(), now it happens here.
>
>>> buf[0] = ((if_ctl >> 16) & 0xff);
>>> buf[1] = ((if_ctl >> 8) & 0xff);
>>> buf[2] = ((if_ctl >> 0) & 0xff);
>>> diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c b/drivers/media/dvb-frontends/cxd2820r_t2.c
>>> index 9c0c4f42175c..35fe364c7182 100644
>>> --- a/drivers/media/dvb-frontends/cxd2820r_t2.c
>>> +++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
>>> @@ -120,7 +120,7 @@ int cxd2820r_set_frontend_t2(struct dvb_frontend *fe)
>>>
>>> num = if_freq / 1000; /* Hz => kHz */
>>> num *= 0x1000000;
>>> - if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
>>> + if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000);
>
> Same here if_ctl is a u32.
>
> Cheers,
> Javi
>
prev parent reply other threads:[~2015-03-20 19:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 11:14 [PATCH 0/4] Consolidate DIV_ROUND_CLOSEST_ULL() Javi Merino
2015-03-20 11:14 ` [PATCH 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL Javi Merino
2015-03-20 13:15 ` Alex Elder
2015-03-20 18:19 ` Emil Velikov
2015-03-20 18:19 ` Emil Velikov
2015-03-20 18:27 ` Javi Merino
2015-03-23 7:41 ` Daniel Vetter
2015-03-23 7:41 ` Daniel Vetter
2015-03-23 12:34 ` Jeff Epler
2015-03-23 17:04 ` Javi Merino
2015-03-23 17:04 ` Javi Merino
2015-03-24 11:49 ` Javi Merino
2015-03-24 11:49 ` Javi Merino
2015-03-20 11:14 ` [PATCH 2/4] clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL() Javi Merino
2015-03-20 11:14 ` [PATCH 3/4] cpuidle: menu: " Javi Merino
2015-03-20 11:14 ` [PATCH 4/4] media: cxd2820r: " Javi Merino
2015-03-20 11:17 ` Antti Palosaari
2015-03-20 13:51 ` Alex Elder
2015-03-20 17:27 ` Javi Merino
2015-03-20 19:46 ` Alex Elder [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=550C78FE.3060908@ieee.org \
--to=elder@ieee.org \
--cc=akpm@linux-foundation.org \
--cc=crope@iki.fi \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=javi.merino@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@osg.samsung.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.