lkml.org 
[lkml]   [2021]   [Feb]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] ntp: use memset and offsetof init
Date
On Wed, Jan 20 2021 at 10:51, Yejune Deng wrote:
> In pps_fill_timex(), use memset and offsetof instead of '= 0'.
>
> Signed-off-by: Yejune Deng <yejune.deng@gmail.com>
> ---
> kernel/time/ntp.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
> index 87389b9e21ab..3416c0381104 100644
> --- a/kernel/time/ntp.c
> +++ b/kernel/time/ntp.c
> @@ -225,14 +225,11 @@ static inline int is_error_status(int status)
> static inline void pps_fill_timex(struct __kernel_timex *txc)
> {
> /* PPS is not implemented, so these are zero */
> - txc->ppsfreq = 0;
> - txc->jitter = 0;
> - txc->shift = 0;
> - txc->stabil = 0;
> - txc->jitcnt = 0;
> - txc->calcnt = 0;
> - txc->errcnt = 0;
> - txc->stbcnt = 0;
> + int offset, len;
> +
> + offset = offsetof(struct __kernel_timex, ppsfreq);
> + len = offsetof(struct __kernel_timex, tai) - offset;
> + memset(txc + offset, 0, len);

That zeros bytes at a memory location which is

(offset) * sizeof(struct __kernel_timex)

bytes away from txc. How did this every boot?

And no, even if you fix that pointer math problem then this kind of
calculation from the middle of a struct is error prone.

Thanks,

tglx

\
 
 \ /
  Last update: 2021-02-05 20:34    [W:0.060 / U:3.720 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site