diff mbox series

[1/4] media: dvb-frontends: Use DIV_ROUND_CLOSEST directly to make it readable

Message ID 1567700092-27769-2-git-send-email-zhongjiang@huawei.com (mailing list archive)
State New, archived
Headers show
Series media: Use DIV_ROUND_CLOSEST directly | expand

Commit Message

zhong jiang Sept. 5, 2019, 4:14 p.m. UTC
The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
but is perhaps more readable.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 drivers/media/dvb-frontends/mt312.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Sean Young Oct. 1, 2019, 11:15 a.m. UTC | #1
Hi,

On Fri, Sep 06, 2019 at 12:14:49AM +0800, zhong jiang wrote:
> The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
> but is perhaps more readable.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  drivers/media/dvb-frontends/mt312.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/dvb-frontends/mt312.c b/drivers/media/dvb-frontends/mt312.c
> index 7cae7d6..251ff41 100644
> --- a/drivers/media/dvb-frontends/mt312.c
> +++ b/drivers/media/dvb-frontends/mt312.c
> @@ -137,7 +137,7 @@ static inline int mt312_writereg(struct mt312_state *state,
>  
>  static inline u32 mt312_div(u32 a, u32 b)
>  {
> -	return (a + (b / 2)) / b;
> +	return DIV_ROUND_CLOSEST(a, b);

Well spotted, that is absolutely correct. However now mt312_div() is just
a wrapper for DIV_ROUND_CLOSEST() -- and even marked inline. Really all
the callers to mt312_div() should be replaced with DIV_ROUND_CLOSEST().

Thanks,

Sean
zhong jiang Oct. 9, 2019, 2:24 p.m. UTC | #2
On 2019/10/1 19:15, Sean Young wrote:
> Hi,
>
> On Fri, Sep 06, 2019 at 12:14:49AM +0800, zhong jiang wrote:
>> The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
>> but is perhaps more readable.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>>  drivers/media/dvb-frontends/mt312.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/dvb-frontends/mt312.c b/drivers/media/dvb-frontends/mt312.c
>> index 7cae7d6..251ff41 100644
>> --- a/drivers/media/dvb-frontends/mt312.c
>> +++ b/drivers/media/dvb-frontends/mt312.c
>> @@ -137,7 +137,7 @@ static inline int mt312_writereg(struct mt312_state *state,
>>  
>>  static inline u32 mt312_div(u32 a, u32 b)
>>  {
>> -	return (a + (b / 2)) / b;
>> +	return DIV_ROUND_CLOSEST(a, b);
> Well spotted, that is absolutely correct. However now mt312_div() is just
> a wrapper for DIV_ROUND_CLOSEST() -- and even marked inline. Really all
> the callers to mt312_div() should be replaced with DIV_ROUND_CLOSEST().
Thanks for your suggestion.   I will use DIV_ROUND_CLOSEST directly in v2.

Sincerely,
zhong jiang
> Thanks,
>
> Sean
>
> .
>
diff mbox series

Patch

diff --git a/drivers/media/dvb-frontends/mt312.c b/drivers/media/dvb-frontends/mt312.c
index 7cae7d6..251ff41 100644
--- a/drivers/media/dvb-frontends/mt312.c
+++ b/drivers/media/dvb-frontends/mt312.c
@@ -137,7 +137,7 @@  static inline int mt312_writereg(struct mt312_state *state,
 
 static inline u32 mt312_div(u32 a, u32 b)
 {
-	return (a + (b / 2)) / b;
+	return DIV_ROUND_CLOSEST(a, b);
 }
 
 static int mt312_reset(struct mt312_state *state, const u8 full)