Re: class_device_create_file warnings during compilation

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

 



warn_unused_result
Found in versions: 3.3 3.4
Description:
The `warn_unused_result' attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value.  This is useful for functions where not checking the result is either a security problem or always a bug, such as `realloc'.

          int fn () __attribute__ ((warn_unused_result));
          int foo ()
          {
            if (fn () < 0) return -1;
            fn ();
            return 0;
          }

     results in warning on line 5.
On 3/15/07, Prasad Joshi <prasadjoshi124@xxxxxxxxx> wrote:
Hi Dinesh,
 
Some functions in the linux kernel are marked with must_check attribute. For eg. copy_to/from_user () is declared something like this.
 
unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n);
 
__must_check attribute indicates for functions for which checking the return value is mantadory.
 
This must have been the case with the function class_device_create_file().

Thanks and Regards,
Prasad.
 
On 3/15/07, Mike Frysinger <vapier.adi@xxxxxxxxx> wrote:
On 3/14/07, Dinesh <dbhat@xxxxxxxxx> wrote:
> When I compile our drivers on 2.6.19, I get the following warning message.
>
> warning: ignoring return value of 'class_device_create_file', declared
> with attribute warn_unused_result
>
> The driver does not print any warnings on 2.6.17 and it appears that
> this is related to some sysfs entries.

that's because 2.6.19 was improved to print warnings when people write
code that fail to properly check the results of functions

> Can anyone please tell me how to get rid of these messages?

going out on a limb here, but dont ignore the result of the function
(aka, the result of the function is unused)

incorrect:
class_device_create_file(...);

correct:
result = class_device_create_file(...);
if (result) ...
-mike

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux