lkml.org 
[lkml]   [2008]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] ioctl conversion
On Fri, Jul 11, 2008 at 3:08 AM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Friday 11 July 2008, Stoyan Gaydarov wrote:
>> - if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC)
>> + lock_kernel();
>> +
>> + if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC) {
>> + unlock_kernel();
>> return -ENOTTY;
>> - if (_IOC_NR(cmd) > SNAPSHOT_IOC_MAXNR)
>> + }
>> + if (_IOC_NR(cmd) > SNAPSHOT_IOC_MAXNR) {
>> + unlock_kernel();
>> return -ENOTTY;
>> - if (!capable(CAP_SYS_ADMIN))
>> + }
>> + if (!capable(CAP_SYS_ADMIN)) {
>> + unlock_kernel();
>> return -EPERM;
>> + }
>>
>> data = filp->private_data;
>
> The more common way to express this is to end the function with
>
> out:
> unlock_kernel();
> return ret;
> }

This would work normally but there are three early returns and the
rest are just switch statements that set the return code.

>
> and then jump to that label in the error case. This makes it
> much easier to verify that you haven't missed a cased.
>
> Arnd <><
>


\
 
 \ /
  Last update: 2008-07-11 10:25    [W:0.039 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site