Skip to content

Commit 9a69645

Browse files
sudipm-mukherjeegregkh
authored andcommitted
ppdev: fix registering same device name
Usually every parallel port will have a single pardev registered with it. But ppdev driver is an exception. This userspace parallel port driver allows to create multiple parrallel port devices for a single parallel port. And as a result we were having a big warning like: "sysfs: cannot create duplicate filename '/devices/parport0/ppdev0.0'". And with that many parallel port printers stopped working. We have been using the minor number as the id field while registering a parralel port device with a parralel port. But when there are multiple parrallel port device for one single parallel port, they all tried to register with the same name like 'pardev0.0' and everything started failing. Use an incremented index as the id instead of the minor number. Fixes: 8b7d3a9 ("ppdev: use new parport device model") Cc: stable <[email protected]> # v4.9+ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1414656 Bugzilla: https://bugs.archlinux.org/task/52322 Tested-by: James Feeney <[email protected]> Signed-off-by: Sudip Mukherjee <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 03270c6 commit 9a69645

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/char/ppdev.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ struct pp_struct {
8484
struct ieee1284_info state;
8585
struct ieee1284_info saved_state;
8686
long default_inactivity;
87+
int index;
8788
};
8889

8990
/* should we use PARDEVICE_MAX here? */
9091
static struct device *devices[PARPORT_MAX];
9192

93+
static DEFINE_IDA(ida_index);
94+
9295
/* pp_struct.flags bitfields */
9396
#define PP_CLAIMED (1<<0)
9497
#define PP_EXCL (1<<1)
@@ -290,7 +293,7 @@ static int register_device(int minor, struct pp_struct *pp)
290293
struct pardevice *pdev = NULL;
291294
char *name;
292295
struct pardev_cb ppdev_cb;
293-
int rc = 0;
296+
int rc = 0, index;
294297

295298
name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
296299
if (name == NULL)
@@ -303,20 +306,23 @@ static int register_device(int minor, struct pp_struct *pp)
303306
goto err;
304307
}
305308

309+
index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL);
306310
memset(&ppdev_cb, 0, sizeof(ppdev_cb));
307311
ppdev_cb.irq_func = pp_irq;
308312
ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0;
309313
ppdev_cb.private = pp;
310-
pdev = parport_register_dev_model(port, name, &ppdev_cb, minor);
314+
pdev = parport_register_dev_model(port, name, &ppdev_cb, index);
311315
parport_put_port(port);
312316

313317
if (!pdev) {
314318
pr_warn("%s: failed to register device!\n", name);
315319
rc = -ENXIO;
320+
ida_simple_remove(&ida_index, index);
316321
goto err;
317322
}
318323

319324
pp->pdev = pdev;
325+
pp->index = index;
320326
dev_dbg(&pdev->dev, "registered pardevice\n");
321327
err:
322328
kfree(name);
@@ -755,6 +761,7 @@ static int pp_release(struct inode *inode, struct file *file)
755761

756762
if (pp->pdev) {
757763
parport_unregister_device(pp->pdev);
764+
ida_simple_remove(&ida_index, pp->index);
758765
pp->pdev = NULL;
759766
pr_debug(CHRDEV "%x: unregistered pardevice\n", minor);
760767
}

0 commit comments

Comments
 (0)