Skip to content

Commit 36eb387

Browse files
authored
Merge pull request #14 from EricccTaiwan/goto
Refactor error handling
2 parents d6d95a2 + 96aa334 commit 36eb387

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

main.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,26 +490,21 @@ static int __init kxo_init(void)
490490
ret = device_create_file(kxo_dev, &dev_attr_kxo_state);
491491
if (ret < 0) {
492492
printk(KERN_ERR "failed to create sysfs file kxo_state\n");
493-
goto error_cdev;
493+
goto error_device;
494494
}
495495

496496
/* Allocate fast circular buffer */
497497
fast_buf.buf = vmalloc(PAGE_SIZE);
498498
if (!fast_buf.buf) {
499-
device_destroy(kxo_class, dev_id);
500-
class_destroy(kxo_class);
501499
ret = -ENOMEM;
502-
goto error_cdev;
500+
goto error_vmalloc;
503501
}
504502

505503
/* Create the workqueue */
506504
kxo_workqueue = alloc_workqueue("kxod", WQ_UNBOUND, WQ_MAX_ACTIVE);
507505
if (!kxo_workqueue) {
508-
vfree(fast_buf.buf);
509-
device_destroy(kxo_class, dev_id);
510-
class_destroy(kxo_class);
511506
ret = -ENOMEM;
512-
goto error_cdev;
507+
goto error_workqueue;
513508
}
514509

515510
negamax_init();
@@ -529,6 +524,12 @@ static int __init kxo_init(void)
529524
pr_info("kxo: registered new kxo device: %d,%d\n", major, 0);
530525
out:
531526
return ret;
527+
error_workqueue:
528+
vfree(fast_buf.buf);
529+
error_vmalloc:
530+
device_destroy(kxo_class, dev_id);
531+
error_device:
532+
class_destroy(kxo_class);
532533
error_cdev:
533534
cdev_del(&kxo_cdev);
534535
error_region:

0 commit comments

Comments
 (0)