2006-08-18 13:18:22

by Michal Piotrowski

[permalink] [raw]
Subject: Question about handling return value of device_create_file function

Hi,

I have noticed that sparse generates a lot of "ignoring return value
of 'device_create_file'" warnings.

(cat sparse.txt | grep -c "device_create_file"
1231 :)

I want to fix this warnings, but I'm wondering how to properly handle
return value of device_create_file function.

The shortest way.

int foo()
{
int error;

[..]

error = device_create_file(&bar, &bas)

if (error)
return error;
}

A bit longer way.

int foo()
{
int error;

[..]

error = device_create_file(&bar, &bas)

if (error) {
subsystem_remove_device(bar);
return error;
}
}

Any hints?

Regards,
Michal

--
Michal K. K. Piotrowski
LTG - Linux Testers Group
(http://www.stardust.webpages.pl/ltg/wiki/)


2006-08-18 14:36:09

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: Question about handling return value of device_create_file function

On 8/18/06, Michal Piotrowski <[email protected]> wrote:
> Hi,
>
> I have noticed that sparse generates a lot of "ignoring return value
> of 'device_create_file'" warnings.
>
> (cat sparse.txt | grep -c "device_create_file"
> 1231 :)
>
> I want to fix this warnings, but I'm wondering how to properly handle
> return value of device_create_file function.
>
> The shortest way.
>
> int foo()
> {
> int error;
>
> [..]
>
> error = device_create_file(&bar, &bas)
>
> if (error)
> return error;
> }
>
> A bit longer way.
>
> int foo()
> {
> int error;
>
> [..]
>
> error = device_create_file(&bar, &bas)
>
> if (error) {
> subsystem_remove_device(bar);
> return error;
> }
> }
>

Normally you should use 2nd form, especially when foo is a
module_init(foo) as you do not want to have a half-registered device
without supporting code in kernel.

--
Dmitry