From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751408AbbCTTqM (ORCPT ); Fri, 20 Mar 2015 15:46:12 -0400 Received: from mail-qc0-f180.google.com ([209.85.216.180]:34223 "EHLO mail-qc0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750925AbbCTTqJ (ORCPT ); Fri, 20 Mar 2015 15:46:09 -0400 Message-ID: <550C78FE.3060908@ieee.org> Date: Fri, 20 Mar 2015 14:46:06 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Javi Merino CC: "akpm@linux-foundation.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , Antti Palosaari , Mauro Carvalho Chehab Subject: Re: [PATCH 4/4] media: cxd2820r: use DIV_ROUND_CLOSEST_ULL() References: <1426850083-11049-1-git-send-email-javi.merino@arm.com> <1426850083-11049-5-git-send-email-javi.merino@arm.com> <550C25E8.70202@ieee.org> <20150320172721.GA31927@e104805> In-Reply-To: <20150320172721.GA31927@e104805> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>> Cc: Mauro Carvalho Chehab >>> Signed-off-by: Javi Merino >>> --- >>> 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 >