Re: [PATCH] no compile warnings from cyclictest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

On Sat, Jun 03, 2017 at 12:01:24PM +0200, rolf.freitag@xxxxxxxx wrote:
> Hi,
> 
> compiling cyclictest gives 4 warnings of type
> 
>   warning: ignoring return value of 'write'
> 
> and three of type
> 
>   warning: ... may be used uninitialized in this function
> 
> So i eleminated the first sort with a trash variable, which adds up 
> the return values and recycles them (their entropy) at the end via
> srand(). This also avoids a write-only variable.
> I eleminated the second sort by initializing the variables.
> 
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -222,6 +222,7 @@ static int use_fifo = 0;
>  static pthread_t fifo_threadid;
>  static int laptop = 0;
>  static int use_histfile = 0;
> +static unsigned int trash; // for unused return values, to avoid compiler warnings because of ignored return values

What is the good reason to collect these in a global variable?
Ah, later in the patch you use it for srand. Is this a good idea? If so,
document it here.

Oh, and AFAIK cyclictest uses C comments, not C++.

>  #ifdef ARCH_HAS_SMI_COUNTER
>  static int smi = 0;
> @@ -491,10 +492,10 @@ static void tracemark(char *fmt, ...)
>         va_end(ap);
>  
>         /* write the tracemark message */
> -       write(tracemark_fd, tracebuf, len);
> +       trash += write(tracemark_fd, tracebuf, len);

IMHO that's not very sensible. The compiler tells you, that you ignore
the return value of write and that might be a bad thing. So the (more)
sensible options are:

 - add proper error checking and let (here) tracemark fail if the write
   fails (and retry if the return value is positive but less than len).

 - you don't care about the return value, so use:

 	(void)write(tracemark_fd, tracebuf, len)

 - keep the warnings until someone else fixes them properly.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux