The use of two separate structs (lirc_dev aka lirc_driver and irctl) makes it much harder to follow the proper lifetime of the various structs and necessitates hacks such as keeping a copy of struct lirc_dev inside struct irctl. Merging the two structs means that lirc_dev can properly manage the lifetime of the resulting struct and simplifies the code at the same time. [mchehab@s-opensource.com: fix merge conflict] Signed-off-by: David Härdeman <david@hardeman.nu> Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Showing the changes to include/media/lirc_dev.h (1 of 4 files). Show all
Unified · Split
| @@ -17,6 +17,8 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <linux/poll.h> |
| 18 | 18 | #include <linux/kfifo.h> |
| 19 | 19 | #include <media/lirc.h> |
| 20 | +#include <linux/device.h> | |
| 21 | +#include <linux/cdev.h> | |
| 20 | 22 | |
| 21 | 23 | struct lirc_buffer { |
| 22 | 24 | wait_queue_head_t wait_poll; |
| @@ -127,14 +129,19 @@ static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf, · 104 unmodified lines | ||
| 127 | 129 | * LIRC_CAN_SET_REC_TIMEOUT is defined. |
| 128 | 130 | * @max_timeout: Maximum timeout for record. Valid only if |
| 129 | 131 | * LIRC_CAN_SET_REC_TIMEOUT is defined. |
| 130 | − * @rbuf: if not NULL, it will be used as a read buffer, you will | |
| 132 | + * @buf: if %NULL, lirc_dev will allocate and manage the buffer, | |
| 133 | + * otherwise allocated by the caller which will | |
| 131 | 134 | * have to write to the buffer by other means, like irq's |
| 132 | 135 | * (see also lirc_serial.c). |
| 136 | + * @buf_internal: whether lirc_dev has allocated the read buffer or not | |
| 133 | 137 | * @rdev: &struct rc_dev associated with the device |
| 134 | 138 | * @fops: &struct file_operations for the device |
| 135 | − * @dev: &struct device assigned to the device | |
| 136 | 139 | * @owner: the module owning this struct |
| 137 | − * @irctl: &struct irctl assigned to the device | |
| 140 | + * @attached: if the device is still live | |
| 141 | + * @open: open count for the device's chardev | |
| 142 | + * @mutex: serialises file_operations calls | |
| 143 | + * @dev: &struct device assigned to the device | |
| 144 | + * @cdev: &struct cdev assigned to the device | |
| 138 | 145 | */ |
| 139 | 146 | struct lirc_dev { |
| 140 | 147 | char name[40]; |
| @@ -144,16 +151,23 @@ struct lirc_dev { · 3 unmodified lines | ||
| 144 | 151 | |
| 145 | 152 | unsigned int buffer_size; /* in chunks holding one code each */ |
| 146 | 153 | unsigned int chunk_size; |
| 154 | + struct lirc_buffer *buf; | |
| 155 | + bool buf_internal; | |
| 147 | 156 | |
| 148 | 157 | void *data; |
| 149 | 158 | int min_timeout; |
| 150 | 159 | int max_timeout; |
| 151 | − struct lirc_buffer *rbuf; | |
| 152 | 160 | struct rc_dev *rdev; |
| 153 | 161 | const struct file_operations *fops; |
| 154 | − struct device *dev; | |
| 155 | 162 | struct module *owner; |
| 156 | − struct irctl *irctl; | |
| 163 | + | |
| 164 | + bool attached; | |
| 165 | + int open; | |
| 166 | + | |
| 167 | + struct mutex mutex; /* protect from simultaneous accesses */ | |
| 168 | + | |
| 169 | + struct device dev; | |
| 170 | + struct cdev cdev; | |
| 157 | 171 | }; |
| 158 | 172 | |
| 159 | 173 | struct lirc_dev *lirc_allocate_device(void); |