xref: /linux/drivers/s390/char/hmcdrv_dev.c (revision 8f933b1043e1e51f4776fc1ffe86752c7785fd4e)
1*8f933b10SRalf Hoppe /*
2*8f933b10SRalf Hoppe  *    HMC Drive CD/DVD Device
3*8f933b10SRalf Hoppe  *
4*8f933b10SRalf Hoppe  *    Copyright IBM Corp. 2013
5*8f933b10SRalf Hoppe  *    Author(s): Ralf Hoppe (rhoppe@de.ibm.com)
6*8f933b10SRalf Hoppe  *
7*8f933b10SRalf Hoppe  *    This file provides a Linux "misc" character device for access to an
8*8f933b10SRalf Hoppe  *    assigned HMC drive CD/DVD-ROM. It works as follows: First create the
9*8f933b10SRalf Hoppe  *    device by calling hmcdrv_dev_init(). After open() a lseek(fd, 0,
10*8f933b10SRalf Hoppe  *    SEEK_END) indicates that a new FTP command follows (not needed on the
11*8f933b10SRalf Hoppe  *    first command after open). Then write() the FTP command ASCII string
12*8f933b10SRalf Hoppe  *    to it, e.g. "dir /" or "nls <directory>" or "get <filename>". At the
13*8f933b10SRalf Hoppe  *    end read() the response.
14*8f933b10SRalf Hoppe  */
15*8f933b10SRalf Hoppe 
16*8f933b10SRalf Hoppe #define KMSG_COMPONENT "hmcdrv"
17*8f933b10SRalf Hoppe #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
18*8f933b10SRalf Hoppe 
19*8f933b10SRalf Hoppe #include <linux/kernel.h>
20*8f933b10SRalf Hoppe #include <linux/module.h>
21*8f933b10SRalf Hoppe #include <linux/slab.h>
22*8f933b10SRalf Hoppe #include <linux/fs.h>
23*8f933b10SRalf Hoppe #include <linux/cdev.h>
24*8f933b10SRalf Hoppe #include <linux/miscdevice.h>
25*8f933b10SRalf Hoppe #include <linux/device.h>
26*8f933b10SRalf Hoppe #include <linux/capability.h>
27*8f933b10SRalf Hoppe #include <linux/delay.h>
28*8f933b10SRalf Hoppe #include <linux/uaccess.h>
29*8f933b10SRalf Hoppe 
30*8f933b10SRalf Hoppe #include "hmcdrv_dev.h"
31*8f933b10SRalf Hoppe #include "hmcdrv_ftp.h"
32*8f933b10SRalf Hoppe 
33*8f933b10SRalf Hoppe /* If the following macro is defined, then the HMC device creates it's own
34*8f933b10SRalf Hoppe  * separated device class (and dynamically assigns a major number). If not
35*8f933b10SRalf Hoppe  * defined then the HMC device is assigned to the "misc" class devices.
36*8f933b10SRalf Hoppe  *
37*8f933b10SRalf Hoppe #define HMCDRV_DEV_CLASS "hmcftp"
38*8f933b10SRalf Hoppe  */
39*8f933b10SRalf Hoppe 
40*8f933b10SRalf Hoppe #define HMCDRV_DEV_NAME  "hmcdrv"
41*8f933b10SRalf Hoppe #define HMCDRV_DEV_BUSY_DELAY	 500 /* delay between -EBUSY trials in ms */
42*8f933b10SRalf Hoppe #define HMCDRV_DEV_BUSY_RETRIES  3   /* number of retries on -EBUSY */
43*8f933b10SRalf Hoppe 
44*8f933b10SRalf Hoppe struct hmcdrv_dev_node {
45*8f933b10SRalf Hoppe 
46*8f933b10SRalf Hoppe #ifdef HMCDRV_DEV_CLASS
47*8f933b10SRalf Hoppe 	struct cdev dev; /* character device structure */
48*8f933b10SRalf Hoppe 	umode_t mode;	 /* mode of device node (unused, zero) */
49*8f933b10SRalf Hoppe #else
50*8f933b10SRalf Hoppe 	struct miscdevice dev; /* "misc" device structure */
51*8f933b10SRalf Hoppe #endif
52*8f933b10SRalf Hoppe 
53*8f933b10SRalf Hoppe };
54*8f933b10SRalf Hoppe 
55*8f933b10SRalf Hoppe static int hmcdrv_dev_open(struct inode *inode, struct file *fp);
56*8f933b10SRalf Hoppe static int hmcdrv_dev_release(struct inode *inode, struct file *fp);
57*8f933b10SRalf Hoppe static loff_t hmcdrv_dev_seek(struct file *fp, loff_t pos, int whence);
58*8f933b10SRalf Hoppe static ssize_t hmcdrv_dev_read(struct file *fp, char __user *ubuf,
59*8f933b10SRalf Hoppe 			       size_t len, loff_t *pos);
60*8f933b10SRalf Hoppe static ssize_t hmcdrv_dev_write(struct file *fp, const char __user *ubuf,
61*8f933b10SRalf Hoppe 				size_t len, loff_t *pos);
62*8f933b10SRalf Hoppe static ssize_t hmcdrv_dev_transfer(char __kernel *cmd, loff_t offset,
63*8f933b10SRalf Hoppe 				   char __user *buf, size_t len);
64*8f933b10SRalf Hoppe 
65*8f933b10SRalf Hoppe /*
66*8f933b10SRalf Hoppe  * device operations
67*8f933b10SRalf Hoppe  */
68*8f933b10SRalf Hoppe static const struct file_operations hmcdrv_dev_fops = {
69*8f933b10SRalf Hoppe 	.open = hmcdrv_dev_open,
70*8f933b10SRalf Hoppe 	.llseek = hmcdrv_dev_seek,
71*8f933b10SRalf Hoppe 	.release = hmcdrv_dev_release,
72*8f933b10SRalf Hoppe 	.read = hmcdrv_dev_read,
73*8f933b10SRalf Hoppe 	.write = hmcdrv_dev_write,
74*8f933b10SRalf Hoppe };
75*8f933b10SRalf Hoppe 
76*8f933b10SRalf Hoppe static struct hmcdrv_dev_node hmcdrv_dev; /* HMC device struct (static) */
77*8f933b10SRalf Hoppe 
78*8f933b10SRalf Hoppe #ifdef HMCDRV_DEV_CLASS
79*8f933b10SRalf Hoppe 
80*8f933b10SRalf Hoppe static struct class *hmcdrv_dev_class; /* device class pointer */
81*8f933b10SRalf Hoppe static dev_t hmcdrv_dev_no; /* device number (major/minor) */
82*8f933b10SRalf Hoppe 
83*8f933b10SRalf Hoppe /**
84*8f933b10SRalf Hoppe  * hmcdrv_dev_name() - provides a naming hint for a device node in /dev
85*8f933b10SRalf Hoppe  * @dev: device for which the naming/mode hint is
86*8f933b10SRalf Hoppe  * @mode: file mode for device node created in /dev
87*8f933b10SRalf Hoppe  *
88*8f933b10SRalf Hoppe  * See: devtmpfs.c, function devtmpfs_create_node()
89*8f933b10SRalf Hoppe  *
90*8f933b10SRalf Hoppe  * Return: recommended device file name in /dev
91*8f933b10SRalf Hoppe  */
92*8f933b10SRalf Hoppe static char *hmcdrv_dev_name(struct device *dev, umode_t *mode)
93*8f933b10SRalf Hoppe {
94*8f933b10SRalf Hoppe 	char *nodename = NULL;
95*8f933b10SRalf Hoppe 	const char *devname = dev_name(dev); /* kernel device name */
96*8f933b10SRalf Hoppe 
97*8f933b10SRalf Hoppe 	if (devname)
98*8f933b10SRalf Hoppe 		nodename = kasprintf(GFP_KERNEL, "%s", devname);
99*8f933b10SRalf Hoppe 
100*8f933b10SRalf Hoppe 	/* on device destroy (rmmod) the mode pointer may be NULL
101*8f933b10SRalf Hoppe 	 */
102*8f933b10SRalf Hoppe 	if (mode)
103*8f933b10SRalf Hoppe 		*mode = hmcdrv_dev.mode;
104*8f933b10SRalf Hoppe 
105*8f933b10SRalf Hoppe 	return nodename;
106*8f933b10SRalf Hoppe }
107*8f933b10SRalf Hoppe 
108*8f933b10SRalf Hoppe #endif	/* HMCDRV_DEV_CLASS */
109*8f933b10SRalf Hoppe 
110*8f933b10SRalf Hoppe /*
111*8f933b10SRalf Hoppe  * open()
112*8f933b10SRalf Hoppe  */
113*8f933b10SRalf Hoppe static int hmcdrv_dev_open(struct inode *inode, struct file *fp)
114*8f933b10SRalf Hoppe {
115*8f933b10SRalf Hoppe 	int rc;
116*8f933b10SRalf Hoppe 
117*8f933b10SRalf Hoppe 	/* check for non-blocking access, which is really unsupported
118*8f933b10SRalf Hoppe 	 */
119*8f933b10SRalf Hoppe 	if (fp->f_flags & O_NONBLOCK)
120*8f933b10SRalf Hoppe 		return -EINVAL;
121*8f933b10SRalf Hoppe 
122*8f933b10SRalf Hoppe 	/* Because it makes no sense to open this device read-only (then a
123*8f933b10SRalf Hoppe 	 * FTP command cannot be emitted), we respond with an error.
124*8f933b10SRalf Hoppe 	 */
125*8f933b10SRalf Hoppe 	if ((fp->f_flags & O_ACCMODE) == O_RDONLY)
126*8f933b10SRalf Hoppe 		return -EINVAL;
127*8f933b10SRalf Hoppe 
128*8f933b10SRalf Hoppe 	/* prevent unloading this module as long as anyone holds the
129*8f933b10SRalf Hoppe 	 * device file open - so increment the reference count here
130*8f933b10SRalf Hoppe 	 */
131*8f933b10SRalf Hoppe 	if (!try_module_get(THIS_MODULE))
132*8f933b10SRalf Hoppe 		return -ENODEV;
133*8f933b10SRalf Hoppe 
134*8f933b10SRalf Hoppe 	fp->private_data = NULL; /* no command yet */
135*8f933b10SRalf Hoppe 	rc = hmcdrv_ftp_startup();
136*8f933b10SRalf Hoppe 	if (rc)
137*8f933b10SRalf Hoppe 		module_put(THIS_MODULE);
138*8f933b10SRalf Hoppe 
139*8f933b10SRalf Hoppe 	pr_debug("open file '/dev/%s' with return code %d\n",
140*8f933b10SRalf Hoppe 		 fp->f_dentry->d_name.name, rc);
141*8f933b10SRalf Hoppe 	return rc;
142*8f933b10SRalf Hoppe }
143*8f933b10SRalf Hoppe 
144*8f933b10SRalf Hoppe /*
145*8f933b10SRalf Hoppe  * release()
146*8f933b10SRalf Hoppe  */
147*8f933b10SRalf Hoppe static int hmcdrv_dev_release(struct inode *inode, struct file *fp)
148*8f933b10SRalf Hoppe {
149*8f933b10SRalf Hoppe 	pr_debug("closing file '/dev/%s'\n", fp->f_dentry->d_name.name);
150*8f933b10SRalf Hoppe 	kfree(fp->private_data);
151*8f933b10SRalf Hoppe 	fp->private_data = NULL;
152*8f933b10SRalf Hoppe 	hmcdrv_ftp_shutdown();
153*8f933b10SRalf Hoppe 	module_put(THIS_MODULE);
154*8f933b10SRalf Hoppe 	return 0;
155*8f933b10SRalf Hoppe }
156*8f933b10SRalf Hoppe 
157*8f933b10SRalf Hoppe /*
158*8f933b10SRalf Hoppe  * lseek()
159*8f933b10SRalf Hoppe  */
160*8f933b10SRalf Hoppe static loff_t hmcdrv_dev_seek(struct file *fp, loff_t pos, int whence)
161*8f933b10SRalf Hoppe {
162*8f933b10SRalf Hoppe 	switch (whence) {
163*8f933b10SRalf Hoppe 	case SEEK_CUR: /* relative to current file position */
164*8f933b10SRalf Hoppe 		pos += fp->f_pos; /* new position stored in 'pos' */
165*8f933b10SRalf Hoppe 		break;
166*8f933b10SRalf Hoppe 
167*8f933b10SRalf Hoppe 	case SEEK_SET: /* absolute (relative to beginning of file) */
168*8f933b10SRalf Hoppe 		break; /* SEEK_SET */
169*8f933b10SRalf Hoppe 
170*8f933b10SRalf Hoppe 		/* We use SEEK_END as a special indicator for a SEEK_SET
171*8f933b10SRalf Hoppe 		 * (set absolute position), combined with a FTP command
172*8f933b10SRalf Hoppe 		 * clear.
173*8f933b10SRalf Hoppe 		 */
174*8f933b10SRalf Hoppe 	case SEEK_END:
175*8f933b10SRalf Hoppe 		if (fp->private_data) {
176*8f933b10SRalf Hoppe 			kfree(fp->private_data);
177*8f933b10SRalf Hoppe 			fp->private_data = NULL;
178*8f933b10SRalf Hoppe 		}
179*8f933b10SRalf Hoppe 
180*8f933b10SRalf Hoppe 		break; /* SEEK_END */
181*8f933b10SRalf Hoppe 
182*8f933b10SRalf Hoppe 	default: /* SEEK_DATA, SEEK_HOLE: unsupported */
183*8f933b10SRalf Hoppe 		return -EINVAL;
184*8f933b10SRalf Hoppe 	}
185*8f933b10SRalf Hoppe 
186*8f933b10SRalf Hoppe 	if (pos < 0)
187*8f933b10SRalf Hoppe 		return -EINVAL;
188*8f933b10SRalf Hoppe 
189*8f933b10SRalf Hoppe 	if (fp->f_pos != pos)
190*8f933b10SRalf Hoppe 		++fp->f_version;
191*8f933b10SRalf Hoppe 
192*8f933b10SRalf Hoppe 	fp->f_pos = pos;
193*8f933b10SRalf Hoppe 	return pos;
194*8f933b10SRalf Hoppe }
195*8f933b10SRalf Hoppe 
196*8f933b10SRalf Hoppe /*
197*8f933b10SRalf Hoppe  * transfer (helper function)
198*8f933b10SRalf Hoppe  */
199*8f933b10SRalf Hoppe static ssize_t hmcdrv_dev_transfer(char __kernel *cmd, loff_t offset,
200*8f933b10SRalf Hoppe 				   char __user *buf, size_t len)
201*8f933b10SRalf Hoppe {
202*8f933b10SRalf Hoppe 	ssize_t retlen;
203*8f933b10SRalf Hoppe 	unsigned trials = HMCDRV_DEV_BUSY_RETRIES;
204*8f933b10SRalf Hoppe 
205*8f933b10SRalf Hoppe 	do {
206*8f933b10SRalf Hoppe 		retlen = hmcdrv_ftp_cmd(cmd, offset, buf, len);
207*8f933b10SRalf Hoppe 
208*8f933b10SRalf Hoppe 		if (retlen != -EBUSY)
209*8f933b10SRalf Hoppe 			break;
210*8f933b10SRalf Hoppe 
211*8f933b10SRalf Hoppe 		msleep(HMCDRV_DEV_BUSY_DELAY);
212*8f933b10SRalf Hoppe 
213*8f933b10SRalf Hoppe 	} while (--trials > 0);
214*8f933b10SRalf Hoppe 
215*8f933b10SRalf Hoppe 	return retlen;
216*8f933b10SRalf Hoppe }
217*8f933b10SRalf Hoppe 
218*8f933b10SRalf Hoppe /*
219*8f933b10SRalf Hoppe  * read()
220*8f933b10SRalf Hoppe  */
221*8f933b10SRalf Hoppe static ssize_t hmcdrv_dev_read(struct file *fp, char __user *ubuf,
222*8f933b10SRalf Hoppe 			       size_t len, loff_t *pos)
223*8f933b10SRalf Hoppe {
224*8f933b10SRalf Hoppe 	ssize_t retlen;
225*8f933b10SRalf Hoppe 
226*8f933b10SRalf Hoppe 	if (((fp->f_flags & O_ACCMODE) == O_WRONLY) ||
227*8f933b10SRalf Hoppe 	    (fp->private_data == NULL)) { /* no FTP cmd defined ? */
228*8f933b10SRalf Hoppe 		return -EBADF;
229*8f933b10SRalf Hoppe 	}
230*8f933b10SRalf Hoppe 
231*8f933b10SRalf Hoppe 	retlen = hmcdrv_dev_transfer((char *) fp->private_data,
232*8f933b10SRalf Hoppe 				     *pos, ubuf, len);
233*8f933b10SRalf Hoppe 
234*8f933b10SRalf Hoppe 	pr_debug("read from file '/dev/%s' at %lld returns %zd/%zu\n",
235*8f933b10SRalf Hoppe 		 fp->f_dentry->d_name.name, (long long) *pos, retlen, len);
236*8f933b10SRalf Hoppe 
237*8f933b10SRalf Hoppe 	if (retlen > 0)
238*8f933b10SRalf Hoppe 		*pos += retlen;
239*8f933b10SRalf Hoppe 
240*8f933b10SRalf Hoppe 	return retlen;
241*8f933b10SRalf Hoppe }
242*8f933b10SRalf Hoppe 
243*8f933b10SRalf Hoppe /*
244*8f933b10SRalf Hoppe  * write()
245*8f933b10SRalf Hoppe  */
246*8f933b10SRalf Hoppe static ssize_t hmcdrv_dev_write(struct file *fp, const char __user *ubuf,
247*8f933b10SRalf Hoppe 				size_t len, loff_t *pos)
248*8f933b10SRalf Hoppe {
249*8f933b10SRalf Hoppe 	ssize_t retlen;
250*8f933b10SRalf Hoppe 
251*8f933b10SRalf Hoppe 	pr_debug("writing file '/dev/%s' at pos. %lld with length %zd\n",
252*8f933b10SRalf Hoppe 		 fp->f_dentry->d_name.name, (long long) *pos, len);
253*8f933b10SRalf Hoppe 
254*8f933b10SRalf Hoppe 	if (!fp->private_data) { /* first expect a cmd write */
255*8f933b10SRalf Hoppe 		fp->private_data = kmalloc(len + 1, GFP_KERNEL);
256*8f933b10SRalf Hoppe 
257*8f933b10SRalf Hoppe 		if (!fp->private_data)
258*8f933b10SRalf Hoppe 			return -ENOMEM;
259*8f933b10SRalf Hoppe 
260*8f933b10SRalf Hoppe 		if (!copy_from_user(fp->private_data, ubuf, len)) {
261*8f933b10SRalf Hoppe 			((char *)fp->private_data)[len] = '\0';
262*8f933b10SRalf Hoppe 			return len;
263*8f933b10SRalf Hoppe 		}
264*8f933b10SRalf Hoppe 
265*8f933b10SRalf Hoppe 		kfree(fp->private_data);
266*8f933b10SRalf Hoppe 		fp->private_data = NULL;
267*8f933b10SRalf Hoppe 		return -EFAULT;
268*8f933b10SRalf Hoppe 	}
269*8f933b10SRalf Hoppe 
270*8f933b10SRalf Hoppe 	retlen = hmcdrv_dev_transfer((char *) fp->private_data,
271*8f933b10SRalf Hoppe 				     *pos, (char __user *) ubuf, len);
272*8f933b10SRalf Hoppe 	if (retlen > 0)
273*8f933b10SRalf Hoppe 		*pos += retlen;
274*8f933b10SRalf Hoppe 
275*8f933b10SRalf Hoppe 	pr_debug("write to file '/dev/%s' returned %zd\n",
276*8f933b10SRalf Hoppe 		 fp->f_dentry->d_name.name, retlen);
277*8f933b10SRalf Hoppe 
278*8f933b10SRalf Hoppe 	return retlen;
279*8f933b10SRalf Hoppe }
280*8f933b10SRalf Hoppe 
281*8f933b10SRalf Hoppe /**
282*8f933b10SRalf Hoppe  * hmcdrv_dev_init() - creates a HMC drive CD/DVD device
283*8f933b10SRalf Hoppe  *
284*8f933b10SRalf Hoppe  * This function creates a HMC drive CD/DVD kernel device and an associated
285*8f933b10SRalf Hoppe  * device under /dev, using a dynamically allocated major number.
286*8f933b10SRalf Hoppe  *
287*8f933b10SRalf Hoppe  * Return: 0 on success, else an error code.
288*8f933b10SRalf Hoppe  */
289*8f933b10SRalf Hoppe int hmcdrv_dev_init(void)
290*8f933b10SRalf Hoppe {
291*8f933b10SRalf Hoppe 	int rc;
292*8f933b10SRalf Hoppe 
293*8f933b10SRalf Hoppe #ifdef HMCDRV_DEV_CLASS
294*8f933b10SRalf Hoppe 	struct device *dev;
295*8f933b10SRalf Hoppe 
296*8f933b10SRalf Hoppe 	rc = alloc_chrdev_region(&hmcdrv_dev_no, 0, 1, HMCDRV_DEV_NAME);
297*8f933b10SRalf Hoppe 
298*8f933b10SRalf Hoppe 	if (rc)
299*8f933b10SRalf Hoppe 		goto out_err;
300*8f933b10SRalf Hoppe 
301*8f933b10SRalf Hoppe 	cdev_init(&hmcdrv_dev.dev, &hmcdrv_dev_fops);
302*8f933b10SRalf Hoppe 	hmcdrv_dev.dev.owner = THIS_MODULE;
303*8f933b10SRalf Hoppe 	rc = cdev_add(&hmcdrv_dev.dev, hmcdrv_dev_no, 1);
304*8f933b10SRalf Hoppe 
305*8f933b10SRalf Hoppe 	if (rc)
306*8f933b10SRalf Hoppe 		goto out_unreg;
307*8f933b10SRalf Hoppe 
308*8f933b10SRalf Hoppe 	/* At this point the character device exists in the kernel (see
309*8f933b10SRalf Hoppe 	 * /proc/devices), but not under /dev nor /sys/devices/virtual. So
310*8f933b10SRalf Hoppe 	 * we have to create an associated class (see /sys/class).
311*8f933b10SRalf Hoppe 	 */
312*8f933b10SRalf Hoppe 	hmcdrv_dev_class = class_create(THIS_MODULE, HMCDRV_DEV_CLASS);
313*8f933b10SRalf Hoppe 
314*8f933b10SRalf Hoppe 	if (IS_ERR(hmcdrv_dev_class)) {
315*8f933b10SRalf Hoppe 		rc = PTR_ERR(hmcdrv_dev_class);
316*8f933b10SRalf Hoppe 		goto out_devdel;
317*8f933b10SRalf Hoppe 	}
318*8f933b10SRalf Hoppe 
319*8f933b10SRalf Hoppe 	/* Finally a device node in /dev has to be established (as 'mkdev'
320*8f933b10SRalf Hoppe 	 * does from the command line). Notice that assignment of a device
321*8f933b10SRalf Hoppe 	 * node name/mode function is optional (only for mode != 0600).
322*8f933b10SRalf Hoppe 	 */
323*8f933b10SRalf Hoppe 	hmcdrv_dev.mode = 0; /* "unset" */
324*8f933b10SRalf Hoppe 	hmcdrv_dev_class->devnode = hmcdrv_dev_name;
325*8f933b10SRalf Hoppe 
326*8f933b10SRalf Hoppe 	dev = device_create(hmcdrv_dev_class, NULL, hmcdrv_dev_no, NULL,
327*8f933b10SRalf Hoppe 			    "%s", HMCDRV_DEV_NAME);
328*8f933b10SRalf Hoppe 	if (!IS_ERR(dev))
329*8f933b10SRalf Hoppe 		return 0;
330*8f933b10SRalf Hoppe 
331*8f933b10SRalf Hoppe 	rc = PTR_ERR(dev);
332*8f933b10SRalf Hoppe 	class_destroy(hmcdrv_dev_class);
333*8f933b10SRalf Hoppe 	hmcdrv_dev_class = NULL;
334*8f933b10SRalf Hoppe 
335*8f933b10SRalf Hoppe out_devdel:
336*8f933b10SRalf Hoppe 	cdev_del(&hmcdrv_dev.dev);
337*8f933b10SRalf Hoppe 
338*8f933b10SRalf Hoppe out_unreg:
339*8f933b10SRalf Hoppe 	unregister_chrdev_region(hmcdrv_dev_no, 1);
340*8f933b10SRalf Hoppe 
341*8f933b10SRalf Hoppe out_err:
342*8f933b10SRalf Hoppe 
343*8f933b10SRalf Hoppe #else  /* !HMCDRV_DEV_CLASS */
344*8f933b10SRalf Hoppe 	hmcdrv_dev.dev.minor = MISC_DYNAMIC_MINOR;
345*8f933b10SRalf Hoppe 	hmcdrv_dev.dev.name = HMCDRV_DEV_NAME;
346*8f933b10SRalf Hoppe 	hmcdrv_dev.dev.fops = &hmcdrv_dev_fops;
347*8f933b10SRalf Hoppe 	hmcdrv_dev.dev.mode = 0; /* finally produces 0600 */
348*8f933b10SRalf Hoppe 	rc = misc_register(&hmcdrv_dev.dev);
349*8f933b10SRalf Hoppe #endif	/* HMCDRV_DEV_CLASS */
350*8f933b10SRalf Hoppe 
351*8f933b10SRalf Hoppe 	return rc;
352*8f933b10SRalf Hoppe }
353*8f933b10SRalf Hoppe 
354*8f933b10SRalf Hoppe /**
355*8f933b10SRalf Hoppe  * hmcdrv_dev_exit() - destroys a HMC drive CD/DVD device
356*8f933b10SRalf Hoppe  */
357*8f933b10SRalf Hoppe void hmcdrv_dev_exit(void)
358*8f933b10SRalf Hoppe {
359*8f933b10SRalf Hoppe #ifdef HMCDRV_DEV_CLASS
360*8f933b10SRalf Hoppe 	if (!IS_ERR_OR_NULL(hmcdrv_dev_class)) {
361*8f933b10SRalf Hoppe 		device_destroy(hmcdrv_dev_class, hmcdrv_dev_no);
362*8f933b10SRalf Hoppe 		class_destroy(hmcdrv_dev_class);
363*8f933b10SRalf Hoppe 	}
364*8f933b10SRalf Hoppe 
365*8f933b10SRalf Hoppe 	cdev_del(&hmcdrv_dev.dev);
366*8f933b10SRalf Hoppe 	unregister_chrdev_region(hmcdrv_dev_no, 1);
367*8f933b10SRalf Hoppe #else  /* !HMCDRV_DEV_CLASS */
368*8f933b10SRalf Hoppe 	misc_deregister(&hmcdrv_dev.dev);
369*8f933b10SRalf Hoppe #endif	/* HMCDRV_DEV_CLASS */
370*8f933b10SRalf Hoppe }
371