These two functions only make the logic in lirc_register_driver() harder to follow. (Note that almost no other driver calls kobject_set_name() on their cdev so I simply removed that part).
Showing the changes to drivers/media/rc/lirc_dev.c (1 of 1 file). Show all
Unified · Split
| @@ -65,15 +65,6 @@ static struct irctl *irctls[MAX_IRCTL_DEVICES]; · 64 unmodified lines | ||
| 65 | 65 | /* Only used for sysfs but defined to void otherwise */ |
| 66 | 66 | static struct class *lirc_class; |
| 67 | 67 | |
| 68 | −/* helper function | |
| 69 | − * initializes the irctl structure | |
| 70 | − */ | |
| 71 | −static void lirc_irctl_init(struct irctl *ir) | |
| 72 | −{ | |
| 73 | − mutex_init(&ir->irctl_lock); | |
| 74 | − ir->d.minor = NOPLUG; | |
| 75 | −} | |
| 76 | − | |
| 77 | 68 | static void lirc_release(struct device *ld) |
| 78 | 69 | { |
| 79 | 70 | struct irctl *ir = container_of(ld, struct irctl, dev); |
| @@ -91,27 +82,6 @@ static void lirc_release(struct device *ld) · 11 unmodified lines | ||
| 91 | 82 | kfree(ir); |
| 92 | 83 | } |
| 93 | 84 | |
| 94 | −static int lirc_cdev_add(struct irctl *ir) | |
| 95 | −{ | |
| 96 | − struct lirc_driver *d = &ir->d; | |
| 97 | − struct cdev *cdev; | |
| 98 | − int retval; | |
| 99 | − | |
| 100 | − cdev = &ir->cdev; | |
| 101 | − | |
| 102 | − if (!d->fops) | |
| 103 | − return -EINVAL; | |
| 104 | − | |
| 105 | − cdev_init(cdev, d->fops); | |
| 106 | − cdev->owner = d->owner; | |
| 107 | − retval = kobject_set_name(&cdev->kobj, "lirc%d", d->minor); | |
| 108 | − if (retval) | |
| 109 | − return retval; | |
| 110 | − | |
| 111 | − cdev->kobj.parent = &ir->dev.kobj; | |
| 112 | − return cdev_add(cdev, ir->dev.devt, 1); | |
| 113 | −} | |
| 114 | − | |
| 115 | 85 | static int lirc_allocate_buffer(struct irctl *ir) |
| 116 | 86 | { |
| 117 | 87 | int err = 0; |
| @@ -167,6 +137,11 @@ int lirc_register_driver(struct lirc_driver *d) · 49 unmodified lines | ||
| 167 | 137 | return -EINVAL; |
| 168 | 138 | } |
| 169 | 139 | |
| 140 | + if (!d->fops) { | |
| 141 | + pr_err("fops pointer not filled in!\n"); | |
| 142 | + return -EINVAL; | |
| 143 | + } | |
| 144 | + | |
| 170 | 145 | if (d->minor >= MAX_IRCTL_DEVICES) { |
| 171 | 146 | dev_err(d->dev, "minor must be between 0 and %d!\n", |
| 172 | 147 | MAX_IRCTL_DEVICES - 1); |
| @@ -210,7 +185,8 @@ int lirc_register_driver(struct lirc_driver *d) · 37 unmodified lines | ||
| 210 | 185 | err = -ENOMEM; |
| 211 | 186 | goto out_lock; |
| 212 | 187 | } |
| 213 | − lirc_irctl_init(ir); | |
| 188 | + | |
| 189 | + mutex_init(&ir->irctl_lock); | |
| 214 | 190 | irctls[minor] = ir; |
| 215 | 191 | d->minor = minor; |
| 216 | 192 | |
| @@ -238,7 +214,11 @@ int lirc_register_driver(struct lirc_driver *d) · 21 unmodified lines | ||
| 238 | 214 | ir->dev.release = lirc_release; |
| 239 | 215 | dev_set_name(&ir->dev, "lirc%d", ir->d.minor); |
| 240 | 216 | |
| 241 | − err = lirc_cdev_add(ir); | |
| 217 | + cdev_init(&ir->cdev, d->fops); | |
| 218 | + ir->cdev.owner = ir->d.owner; | |
| 219 | + ir->cdev.kobj.parent = &ir->dev.kobj; | |
| 220 | + | |
| 221 | + err = cdev_add(&ir->cdev, ir->dev.devt, 1); | |
| 242 | 222 | if (err) |
| 243 | 223 | goto out_free_dev; |
| 244 | 224 | |