1 #include <linux/errno.h>
2 #include <linux/miscdevice.h> /* for misc_register, and SYNTH_MINOR */
3 #include <linux/types.h>
4 #include <linux/uaccess.h>
10 #define SYNTH_MINOR 25
13 static int misc_registered
;
14 static int dev_opened
;
16 static ssize_t
speakup_file_write(struct file
*fp
, const char *buffer
,
17 size_t nbytes
, loff_t
*ppos
)
19 size_t count
= nbytes
;
20 const char *ptr
= buffer
;
27 bytes
= min_t(size_t, count
, sizeof(buf
));
28 if (copy_from_user(buf
, ptr
, bytes
))
33 synth_write(buf
, bytes
);
36 return (ssize_t
) nbytes
;
39 static ssize_t
speakup_file_read(struct file
*fp
, char *buf
, size_t nbytes
, loff_t
*ppos
)
44 static int speakup_file_open(struct inode
*ip
, struct file
*fp
)
48 if (xchg(&dev_opened
, 1))
53 static int speakup_file_release(struct inode
*ip
, struct file
*fp
)
59 static struct file_operations synth_fops
= {
60 .read
= speakup_file_read
,
61 .write
= speakup_file_write
,
62 .open
= speakup_file_open
,
63 .release
= speakup_file_release
,
66 static struct miscdevice synth_device
= {
72 void speakup_register_devsynth(void)
74 if (misc_registered
!= 0)
76 /* zero it so if register fails, deregister will not ref invalid ptrs */
77 if (misc_register(&synth_device
))
78 pr_warn("Couldn't initialize miscdevice /dev/synth.\n");
80 pr_info("initialized device: /dev/synth, node (MAJOR %d, MINOR %d)\n", MISC_MAJOR
, SYNTH_MINOR
);
85 void speakup_unregister_devsynth(void)
89 pr_info("speakup: unregistering synth device /dev/synth\n");
90 misc_deregister(&synth_device
);