Commit 8d1ab570 authored by Alexander Viro's avatar Alexander Viro Committed by Jens Axboe

[PATCH] dv1394 devfs use

dv1394.c piles amazing amounts of crap around its devfs entries.
Probably a result of times before devfs_find_and_unregister()...

In any case, code switched to use of devfs_find_and_unregister(),
crapectomy performed...
parent eeab5fdc
...@@ -169,15 +169,6 @@ static spinlock_t dv1394_cards_lock = SPIN_LOCK_UNLOCKED; ...@@ -169,15 +169,6 @@ static spinlock_t dv1394_cards_lock = SPIN_LOCK_UNLOCKED;
static struct hpsb_highlevel *hl_handle; /* = NULL; */ static struct hpsb_highlevel *hl_handle; /* = NULL; */
static LIST_HEAD(dv1394_devfs);
struct dv1394_devfs_entry {
struct list_head list;
devfs_handle_t devfs;
char name[32];
struct dv1394_devfs_entry *parent;
};
static spinlock_t dv1394_devfs_lock = SPIN_LOCK_UNLOCKED;
/* translate from a struct file* to the corresponding struct video_card* */ /* translate from a struct file* to the corresponding struct video_card* */
static inline struct video_card* file_to_video_card(struct file *file) static inline struct video_card* file_to_video_card(struct file *file)
...@@ -2564,135 +2555,42 @@ static struct file_operations dv1394_fops= ...@@ -2564,135 +2555,42 @@ static struct file_operations dv1394_fops=
/*** DEVFS HELPERS *********************************************************/ /*** DEVFS HELPERS *********************************************************/
struct dv1394_devfs_entry *
dv1394_devfs_find( char *name)
{
struct list_head *lh;
struct dv1394_devfs_entry *p;
spin_lock( &dv1394_devfs_lock);
if(!list_empty(&dv1394_devfs)) {
list_for_each(lh, &dv1394_devfs) {
p = list_entry(lh, struct dv1394_devfs_entry, list);
if(!strncmp(p->name, name, sizeof(p->name))) {
goto found;
}
}
}
p = NULL;
found:
spin_unlock( &dv1394_devfs_lock);
return p;
}
#ifdef CONFIG_DEVFS_FS #ifdef CONFIG_DEVFS_FS
static int dv1394_devfs_add_entry(struct video_card *video) static int dv1394_devfs_add_entry(struct video_card *video)
{ {
char buf[32]; char buf[64];
struct dv1394_devfs_entry *p; snprintf(buf, sizeof(buf), "ieee1394/dv/host%d/%s/%s",
struct dv1394_devfs_entry *parent; (video->id>>2),
(video->pal_or_ntsc == DV1394_NTSC ? "NTSC" : "PAL"),
(video->mode == MODE_RECEIVE ? "in" : "out"));
p = kmalloc(sizeof(struct dv1394_devfs_entry), GFP_KERNEL); video->devfs_handle = devfs_register(NULL, buf, DEVFS_FL_NONE,
if(!p) {
printk(KERN_ERR "dv1394: cannot allocate dv1394_devfs_entry\n");
goto err;
}
memset(p, 0, sizeof(struct dv1394_devfs_entry));
snprintf(buf, sizeof(buf), "dv/host%d/%s", (video->id>>2),
(video->pal_or_ntsc == DV1394_NTSC ? "NTSC" : "PAL"));
parent = dv1394_devfs_find(buf);
if (parent == NULL) {
printk(KERN_ERR "dv1394: unable to locate parent devfs of %s\n", buf);
goto err_free;
}
video->devfs_handle = devfs_register(
parent->devfs,
(video->mode == MODE_RECEIVE ? "in" : "out"),
DEVFS_FL_NONE,
IEEE1394_MAJOR, IEEE1394_MAJOR,
IEEE1394_MINOR_BLOCK_DV1394*16 + video->id, IEEE1394_MINOR_BLOCK_DV1394*16 + video->id,
S_IFCHR | S_IRUGO | S_IWUGO, S_IFCHR | S_IRUGO | S_IWUGO,
&dv1394_fops, &dv1394_fops,
(void*) video); (void*) video);
p->devfs = video->devfs_handle; if (video->devfs_handle == NULL) {
printk(KERN_ERR "dv1394: unable to create /dev/%s\n", buf);
if (p->devfs == NULL) { return -ENOMEM;
printk(KERN_ERR "dv1394: unable to create /dev/ieee1394/%s/%s\n",
parent->name,
(video->mode == MODE_RECEIVE ? "in" : "out"));
goto err_free;
} }
spin_lock( &dv1394_devfs_lock);
INIT_LIST_HEAD(&p->list);
list_add_tail(&p->list, &dv1394_devfs);
spin_unlock( &dv1394_devfs_lock);
return 0; return 0;
err_free:
kfree(p);
err:
return -ENOMEM;
} }
static int static int dv1394_devfs_add_dir(char *name)
dv1394_devfs_add_dir( char *name,
struct dv1394_devfs_entry *parent,
struct dv1394_devfs_entry **out)
{ {
struct dv1394_devfs_entry *p; if (!devfs_mk_dir(NULL, name, NULL))
printk(KERN_ERR "dv1394: unable to create /dev/%s\n", name);
p = kmalloc(sizeof(struct dv1394_devfs_entry), GFP_KERNEL); return -ENOMEM;
if(!p) {
printk(KERN_ERR "dv1394: cannot allocate dv1394_devfs_entry\n");
goto err;
}
memset(p, 0, sizeof(struct dv1394_devfs_entry));
if (parent == NULL) {
snprintf(p->name, sizeof(p->name), "%s", name);
p->devfs = devfs_mk_dir(ieee1394_devfs_handle, name, NULL);
} else {
snprintf(p->name, sizeof(p->name), "%s/%s", parent->name, name);
p->devfs = devfs_mk_dir(parent->devfs, name, NULL);
}
if (p->devfs == NULL) {
printk(KERN_ERR "dv1394: unable to create /dev/ieee1394/%s\n", p->name);
goto err_free;
} }
p->parent = parent;
if (out != NULL) *out = p;
spin_lock( &dv1394_devfs_lock);
INIT_LIST_HEAD(&p->list);
list_add_tail(&p->list, &dv1394_devfs);
spin_unlock( &dv1394_devfs_lock);
return 0; return 0;
err_free:
kfree(p);
err:
return -ENOMEM;
} }
void dv1394_devfs_del( char *name) void dv1394_devfs_del(char *name)
{ {
struct dv1394_devfs_entry *p = dv1394_devfs_find(name); char s[64];
if (p != NULL) { sprintf(s, "ieee1394/%s", name);
devfs_unregister(p->devfs); devfs_find_and_unregister(NULL, s, 0, 0, 0, 0);
spin_lock( &dv1394_devfs_lock);
list_del(&p->list);
spin_unlock( &dv1394_devfs_lock);
kfree(p);
}
} }
#endif /* CONFIG_DEVFS_FS */ #endif /* CONFIG_DEVFS_FS */
...@@ -2874,15 +2772,12 @@ static void dv1394_add_host (struct hpsb_host *host) ...@@ -2874,15 +2772,12 @@ static void dv1394_add_host (struct hpsb_host *host)
#endif #endif
#ifdef CONFIG_DEVFS_FS #ifdef CONFIG_DEVFS_FS
{ snprintf(buf, sizeof(buf), "ieee1394/dv/host%d", ohci->id);
struct dv1394_devfs_entry *devfs_entry = dv1394_devfs_find("dv"); dv1394_devfs_add_dir(buf);
if (devfs_entry != NULL) { snprintf(buf, sizeof(buf), "ieee1394/dv/host%d/NTSC", ohci->id);
snprintf(buf, sizeof(buf), "host%d", ohci->id); dv1394_devfs_add_dir(buf);
dv1394_devfs_add_dir(buf, devfs_entry, &devfs_entry); snprintf(buf, sizeof(buf), "ieee1394/dv/host%d/PAL", ohci->id);
dv1394_devfs_add_dir("NTSC", devfs_entry, NULL); dv1394_devfs_add_dir(buf);
dv1394_devfs_add_dir("PAL", devfs_entry, NULL);
}
}
#endif #endif
dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE); dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE);
...@@ -3042,7 +2937,7 @@ static int __init dv1394_init_module(void) ...@@ -3042,7 +2937,7 @@ static int __init dv1394_init_module(void)
} }
#ifdef CONFIG_DEVFS_FS #ifdef CONFIG_DEVFS_FS
if (dv1394_devfs_add_dir("dv", NULL, NULL) < 0) { if (dv1394_devfs_add_dir("ieee1394/dv") < 0) {
printk(KERN_ERR "dv1394: unable to create /dev/ieee1394/dv\n"); printk(KERN_ERR "dv1394: unable to create /dev/ieee1394/dv\n");
ieee1394_unregister_chardev(IEEE1394_MINOR_BLOCK_DV1394); ieee1394_unregister_chardev(IEEE1394_MINOR_BLOCK_DV1394);
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment