diff options
| author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-04 17:48:18 +0200 | 
|---|---|---|
| committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-04 18:39:43 +0200 | 
| commit | 2eaa35293d31075348fe606bef5a58885d8e09a9 (patch) | |
| tree | 3534a35a2ba3523083d322211bc404ea9ec478cb | |
| parent | 92ea475ae6afe103cd5b2e68fdc84f02e3aa1657 (diff) | |
Refactor
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | char.c | 21 | ||||
| -rw-r--r-- | util.h | 7 | 
3 files changed, 17 insertions, 17 deletions
@@ -1,4 +1,4 @@ -KDIR ?= /lib/modules/`uname -r`/build +KDIR ?= linux  default:  	$(MAKE) -C $(KDIR) M=$$PWD @@ -6,5 +6,5 @@ default:  clean:  	$(MAKE) -C $(KDIR) M=$$PWD clean -tags: harddoom.c -	ctags -R $(KDIR) . +tags: pci.c pci.h char.c char.h harddoom_main.c +	ctags -R linux . @@ -1,8 +1,8 @@  #include "char.h" -#include "linux/cdev.h" -#include "linux/device.h" -#include "linux/fs.h" +#include <linux/cdev.h> +#include <linux/device.h> +#include <linux/fs.h>  #include "util.h"  #include "pci.h" @@ -52,16 +52,17 @@ int new_doomdev(struct pci_dev *dev)  	doom_data->cdev = cdev_alloc();  	if (doom_data->cdev == NULL) { -		return -ENOMEM; +		err = -ENOMEM; +		goto error_cdev;  	}  	cdev_init(doom_data->cdev, &doomdev_fops);  	ORFAIL(cdev_add(doom_data->cdev, first, 1), error_add);  	minor = next_minor++;  	devt = MKDEV(major, minor); -	ORFAIL_PTR(device_create(doom_class, NULL, devt, NULL, +	doom_data->device = device_create(doom_class, &dev->dev, devt, NULL,  				"doom%d", minor), -			doom_data->device, error_create); +	ORFAIL_PTR(doom_data->device, error_create);  	pci_set_drvdata(dev, doom_data); @@ -70,6 +71,7 @@ int new_doomdev(struct pci_dev *dev)  error_create:  	cdev_del(doom_data->cdev);  error_add: +error_cdev:  	kfree(doom_data);  error_kmalloc:  	return err; @@ -78,6 +80,7 @@ error_kmalloc:  void destroy_doomdev(struct pci_dev *dev)  {  	struct doom_data *data; +  	data = pci_get_drvdata(dev);  	device_destroy(doom_class, data->device->devt);  	cdev_del(data->cdev); @@ -87,14 +90,12 @@ void destroy_doomdev(struct pci_dev *dev)  int char_init(void)  {  	int err = 0; +  	ORFAIL(alloc_chrdev_region(&first, 0, DOOMDEV_COUNT, DOOMDEV_NAME),  			error_region);  	major = MAJOR(first);  	doom_class = class_create(THIS_MODULE, "doom"); -	if (IS_ERR(doom_class)) { -		err = PTR_ERR(doom_class); -		goto error_create; -	} +	ORFAIL_PTR(doom_class, error_create);  	return 0; @@ -9,11 +9,10 @@  	} \  }) -#define ORFAIL_PTR(cond, lvalue, label) \ +#define ORFAIL_PTR(ptr, label) \  ({ \ -	lvalue = (cond); \ -	if (IS_ERR(lvalue)) { \ -		err = PTR_ERR(lvalue); \ +	if (IS_ERR(ptr)) { \ +		err = PTR_ERR(ptr); \  		goto label; \  	} \  })  |