Commit a518ab9329041411526ab8e05edfda7e2715244f
Committed by
Al Viro
1 parent
ca30bc9952
Exists in
master
and in
4 other branches
[PATCH] tidy up chrdev_open
Use a single goto label for chrdev_put + return error cases. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 1 changed file with 14 additions and 7 deletions Side-by-side Diff
fs/char_dev.c
... | ... | @@ -386,15 +386,22 @@ |
386 | 386 | cdev_put(new); |
387 | 387 | if (ret) |
388 | 388 | return ret; |
389 | + | |
390 | + ret = -ENXIO; | |
389 | 391 | filp->f_op = fops_get(p->ops); |
390 | - if (!filp->f_op) { | |
391 | - cdev_put(p); | |
392 | - return -ENXIO; | |
393 | - } | |
394 | - if (filp->f_op->open) | |
392 | + if (!filp->f_op) | |
393 | + goto out_cdev_put; | |
394 | + | |
395 | + if (filp->f_op->open) { | |
395 | 396 | ret = filp->f_op->open(inode,filp); |
396 | - if (ret) | |
397 | - cdev_put(p); | |
397 | + if (ret) | |
398 | + goto out_cdev_put; | |
399 | + } | |
400 | + | |
401 | + return 0; | |
402 | + | |
403 | + out_cdev_put: | |
404 | + cdev_put(p); | |
398 | 405 | return ret; |
399 | 406 | } |
400 | 407 |