Commit b489fedc authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] devfs_remove() helper

All callers of devfs_find_and_unregister() pass 0 in 6th argument.  All
uses of that function either pass 0 in 3rd and 4th argument (in which
case the 5th is ignored) or pass the existing pathname in the 2nd (in
which case 3rd, 4th and 5th are ignored).  In all cases the first
argument can be trivially made NULL.

devfs_find_and_unregister() is left as-is.  All existing callers
converted to new helper - devfs_remove(pathname).  Said beast does
equivalent of devfs_find_and_unregister(NULL, pathname, 0, 0, 0, 0);
parent 5cbc8588
......@@ -310,7 +310,7 @@ static void __exit cpqarray_exit(void)
put_disk(ida_gendisk[i][j]);
}
}
devfs_find_and_unregister(NULL, "ida", 0, 0, 0, 0);
devfs_remove("ida");
remove_proc_entry("cpqarray", proc_root_driver);
}
......@@ -437,7 +437,7 @@ static int __init cpqarray_init(void)
printk( KERN_ERR "cpqarray: out of memory");
if (!num_cntlrs_reg) {
devfs_find_and_unregister(NULL,"ida",0,0,0,0);
devfs_remove("ida");
remove_proc_entry("cpqarray", proc_root_driver);
return -ENODEV;
}
......
......@@ -1934,7 +1934,7 @@ static int __init aztcd_init(void)
err_out3:
put_disk(azt_disk);
err_out2:
devfs_find_and_unregister(NULL, "aztcd", 0, 0, DEVFS_SPECIAL_BLK, 0);
devfs_remove("aztcd");
err_out:
if ((azt_port == 0x1f0) || (azt_port == 0x170)) {
SWITCH_IDE_MASTER;
......@@ -1947,7 +1947,7 @@ static int __init aztcd_init(void)
static void __exit aztcd_exit(void)
{
devfs_find_and_unregister(NULL, "aztcd", 0, 0, DEVFS_SPECIAL_BLK, 0);
devfs_remove("aztcd");
del_gendisk(azt_disk);
put_disk(azt_disk);
if ((unregister_blkdev(MAJOR_NR, "aztcd") == -EINVAL)) {
......
......@@ -883,7 +883,7 @@ static void __exit gscd_exit(void)
{
CLEAR_TIMER;
devfs_find_and_unregister(NULL, "gscd", 0, 0, DEVFS_SPECIAL_BLK, 0);
devfs_remove("gscd");
del_gendisk(gscd_disk);
put_disk(gscd_disk);
if ((unregister_blkdev(MAJOR_NR, "gscd") == -EINVAL)) {
......
......@@ -2067,7 +2067,7 @@ static int __init optcd_init(void)
static void __exit optcd_exit(void)
{
devfs_find_and_unregister(NULL, "optcd", 0, 0, DEVFS_SPECIAL_BLK, 0);
devfs_remove("optcd");
del_gendisk(optcd_disk);
put_disk(optcd_disk);
if (unregister_blkdev(MAJOR_NR, "optcd") == -EINVAL) {
......
......@@ -1801,7 +1801,7 @@ static int __init sjcd_init(void)
static void __exit sjcd_exit(void)
{
devfs_find_and_unregister(NULL, "sjcd", 0, 0, DEVFS_SPECIAL_BLK, 0);
devfs_remove("sjcd");
del_gendisk(sjcd_disk);
put_disk(sjcd_disk);
release_region(sjcd_base, 4);
......
......@@ -1671,8 +1671,7 @@ static sony535_exit(void)
kfree(sony_buffer);
kfree(last_sony_subcode);
kfree(sony_toc);
devfs_find_and_unregister(NULL, CDU535_HANDLE, 0, 0,
DEVFS_SPECIAL_BLK, 0);
devfs_remove(CDU535_HANDLE);
del_gendisk(cdu_disk);
put_disk(cdu_disk);
blk_cleanup_queue(&sonycd535_queue);
......
......@@ -415,8 +415,6 @@ int init_module(void)
void cleanup_module(void)
{
int i;
char devname[9];
TRACE_FUN(ft_t_flow);
if (unregister_chrdev(QIC117_TAPE_MAJOR, "zft") != 0) {
......@@ -425,18 +423,12 @@ void cleanup_module(void)
TRACE(ft_t_info, "successful");
}
for (i = 0; i < 4; i++) {
sprintf(devname, "qft%i", i);
devfs_find_and_unregister(NULL, devname, QIC117_TAPE_MAJOR, i, DEVFS_SPECIAL_CHR, 0);
sprintf(devname, "nqft%i", i);
devfs_find_and_unregister(NULL, devname, QIC117_TAPE_MAJOR, i + 4, DEVFS_SPECIAL_CHR, 0);
sprintf(devname, "zqft%i", i);
devfs_find_and_unregister(NULL, devname, QIC117_TAPE_MAJOR, i + 16, DEVFS_SPECIAL_CHR, 0);
sprintf(devname, "nzqft%i", i);
devfs_find_and_unregister(NULL, devname, QIC117_TAPE_MAJOR, i + 20, DEVFS_SPECIAL_CHR, 0);
sprintf(devname, "rawqft%i", i);
devfs_find_and_unregister(NULL, devname, QIC117_TAPE_MAJOR, i + 32, DEVFS_SPECIAL_CHR, 0);
sprintf(devname, "nrawqft%i", i);
devfs_find_and_unregister(NULL, devname, QIC117_TAPE_MAJOR, i + 36, DEVFS_SPECIAL_CHR, 0);
devfs_remove("qft%i", i);
devfs_remove("nqft%i", i);
devfs_remove("zqft%i", i);
devfs_remove("nzqft%i", i);
devfs_remove("rawqft%i", i);
devfs_remove("nrawqft%i", i);
}
zft_uninit_mem(); /* release remaining memory, if any */
printk(KERN_INFO "zftape successfully unloaded.\n");
......
......@@ -2766,22 +2766,14 @@ void cleanup_module(void)
if (status_zombie == NO)
qic02_release_resources();
devfs_find_and_unregister(NULL, "ntpqic11", QIC02_TAPE_MAJOR, 2,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(NULL, "tpqic11", QIC02_TAPE_MAJOR, 3,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(NULL, "ntpqic24", QIC02_TAPE_MAJOR, 4,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(NULL, "tpqic24", QIC02_TAPE_MAJOR, 5,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(NULL, "ntpqic120", QIC02_TAPE_MAJOR, 6,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(NULL, "tpqic120", QIC02_TAPE_MAJOR, 7,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(NULL, "ntpqic150", QIC02_TAPE_MAJOR, 8,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(NULL, "tpqic150", QIC02_TAPE_MAJOR, 9,
DEVFS_SPECIAL_CHR, 0);
devfs_remove("ntpqic11");
devfs_remove("tpqic11");
devfs_remove("ntpqic24");
devfs_remove("tpqic24");
devfs_remove("ntpqic120");
devfs_remove("tpqic120");
devfs_remove("ntpqic150");
devfs_remove("tpqic150");
}
int init_module(void)
......
......@@ -2050,14 +2050,7 @@ void tty_register_devfs (struct tty_driver *driver, unsigned int flags, unsigned
void tty_unregister_devfs (struct tty_driver *driver, unsigned minor)
{
#ifdef CONFIG_DEVFS_FS
int idx = minor - driver->minor_start;
char buf[32];
sprintf(buf, driver->name, idx + driver->name_base);
devfs_find_and_unregister(NULL, buf, driver->major, minor,
DEVFS_SPECIAL_CHR, 0);
#endif /* CONFIG_DEVFS_FS */
devfs_remove(driver->name, minor-driver->minor_start+driver->name_base);
}
EXPORT_SYMBOL(tty_register_devfs);
......
......@@ -470,30 +470,24 @@ static struct file_operations vcs_fops = {
.open = vcs_open,
};
static devfs_handle_t devfs_handle;
void vcs_make_devfs (unsigned int index, int unregister)
{
#ifdef CONFIG_DEVFS_FS
char name[8];
sprintf (name, "a%u", index + 1);
if (unregister)
{
devfs_find_and_unregister(devfs_handle, name + 1, 0, 0,
DEVFS_SPECIAL_CHR, 0);
devfs_find_and_unregister(devfs_handle, name, 0, 0,
DEVFS_SPECIAL_CHR, 0);
}
else
{
devfs_register (devfs_handle, name + 1, DEVFS_FL_DEFAULT,
VCS_MAJOR, index + 1,
S_IFCHR | S_IRUSR | S_IWUSR, &vcs_fops, NULL);
devfs_register (devfs_handle, name, DEVFS_FL_DEFAULT,
VCS_MAJOR, index + 129,
S_IFCHR | S_IRUSR | S_IWUSR, &vcs_fops, NULL);
}
if (unregister) {
devfs_remove("vcc/%u", index + 1);
devfs_remove("vcc/a%u", index + 1);
} else {
char name[16];
sprintf(name, "vcc/%u", index + 1);
devfs_register(NULL, name, DEVFS_FL_DEFAULT,
VCS_MAJOR, index + 1,
S_IFCHR | S_IRUSR | S_IWUSR, &vcs_fops, NULL);
sprintf(name, "vcc/a%u", index + 1);
devfs_register(NULL, name, DEVFS_FL_DEFAULT,
VCS_MAJOR, index + 129,
S_IFCHR | S_IRUSR | S_IWUSR, &vcs_fops, NULL);
}
#endif /* CONFIG_DEVFS_FS */
}
......@@ -506,12 +500,9 @@ int __init vcs_init(void)
if (error)
printk("unable to get major %d for vcs device", VCS_MAJOR);
devfs_handle = devfs_mk_dir (NULL, "vcc", NULL);
devfs_register (devfs_handle, "0", DEVFS_FL_DEFAULT,
VCS_MAJOR, 0,
devfs_register(NULL, "vcc/0", DEVFS_FL_DEFAULT, VCS_MAJOR, 0,
S_IFCHR | S_IRUSR | S_IWUSR, &vcs_fops, NULL);
devfs_register (devfs_handle, "a", DEVFS_FL_DEFAULT,
VCS_MAJOR, 128,
devfs_register(NULL, "vcc/a", DEVFS_FL_DEFAULT, VCS_MAJOR, 128,
S_IFCHR | S_IRUSR | S_IWUSR, &vcs_fops, NULL);
return error;
......
......@@ -2588,9 +2588,7 @@ static int dv1394_devfs_add_dir(char *name)
void dv1394_devfs_del(char *name)
{
char s[64];
sprintf(s, "ieee1394/%s", name);
devfs_find_and_unregister(NULL, s, 0, 0, 0, 0);
devfs_remove("ieee1394/%s", name);
}
#endif /* CONFIG_DEVFS_FS */
......
......@@ -1527,7 +1527,7 @@ static void __exit capi_exit(void)
proc_exit();
unregister_chrdev(capi_major, "capi20");
devfs_find_and_unregister(NULL, "isdn/capi20", capi_major, 0, DEVFS_SPECIAL_CHR, 0);
devfs_remove("isdn/capi20");
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
capinc_tty_exit();
......
......@@ -1111,7 +1111,7 @@ void dm_interface_exit(void)
{
dm_hash_exit();
devfs_find_and_unregister(NULL, DM_DIR "/control", 0, 0, 0, 0);
devfs_remove(DM_DIR "/control");
if (misc_deregister(&_dm_misc) < 0)
DMERR("misc_deregister failed for control device");
......
......@@ -42,8 +42,8 @@ void fs3270_devfs_register(tub_t *tubp)
{
char name[16];
sprintf(name, "tub%.4x", tubp->devno);
devfs_register(fs3270_devfs_dir, name, DEVFS_FL_DEFAULT,
sprintf(name, "3270/tub%.4x", tubp->devno);
devfs_register(NULL, name, DEVFS_FL_DEFAULT,
IBM_FS3270_MAJOR, tubp->minor,
S_IFCHR | S_IRUSR | S_IWUSR, &fs3270_fops, NULL);
sprintf(name, "tty%.4x", tubp->devno);
......@@ -53,16 +53,8 @@ void fs3270_devfs_register(tub_t *tubp)
void fs3270_devfs_unregister(tub_t *tubp)
{
char name[16];
sprintf(name, "tub%.4x", tubp->devno);
devfs_find_and_unregister(fs3270_devfs_dir, name,
IBM_FS3270_MAJOR, tubp->minor,
DEVFS_SPECIAL_CHR, 0);
sprintf(name, "tty%.4x", tubp->devno);
devfs_find_and_unregister(fs3270_devfs_dir, name,
IBM_TTY3270_MAJOR, tubp->minor,
DEVFS_SPECIAL_CHR, 0);
devfs_remove("3270/tub%.4x", tubp->devno);
devfs_remove("3270/tty%.4x", tubp->devno);
}
#endif
......
......@@ -1902,6 +1902,20 @@ void devfs_find_and_unregister (devfs_handle_t dir, const char *name,
devfs_put (de);
} /* End Function devfs_find_and_unregister */
void devfs_remove(const char *fmt, ...)
{
char buf[64];
va_list args;
int n;
va_start(args, fmt);
n = vsnprintf(buf, 64, fmt, args);
if (n < 64) {
devfs_handle_t de = devfs_get_handle(NULL, buf, 0, 0, 0, 0);
devfs_unregister(de);
devfs_put(de);
}
}
/**
* devfs_get_flags - Get the flags for a devfs entry.
......@@ -2317,6 +2331,7 @@ EXPORT_SYMBOL(devfs_mk_symlink);
EXPORT_SYMBOL(devfs_mk_dir);
EXPORT_SYMBOL(devfs_get_handle);
EXPORT_SYMBOL(devfs_find_and_unregister);
EXPORT_SYMBOL(devfs_remove);
EXPORT_SYMBOL(devfs_get_flags);
EXPORT_SYMBOL(devfs_set_flags);
EXPORT_SYMBOL(devfs_get_maj_min);
......
......@@ -99,11 +99,8 @@ EXPORT_SYMBOL(devfs_register_tape);
void devfs_unregister_tape(int num)
{
if (num >= 0) {
char name[32];
sprintf(name, "tapes/tape%u", num);
devfs_find_and_unregister(NULL, name, 0, 0, 0, 0);
}
if (num >= 0)
devfs_remove("tapes/tape%u", num);
}
EXPORT_SYMBOL(devfs_unregister_tape);
......
......@@ -254,15 +254,11 @@ static void devfs_remove_partitions(struct gendisk *dev)
devfs_unregister(dev->disk_de);
dev->disk_de = NULL;
if (dev->flags & GENHD_FL_CD) {
char name[64];
sprintf(name, "cdroms/cdrom%d", dev->number);
if (dev->de)
devfs_find_and_unregister(NULL, name, 0, 0, 0, 0);
devfs_remove("cdroms/cdrom%d", dev->number);
devfs_dealloc_unique_number(&cdrom_numspace, dev->number);
} else {
char name[64];
sprintf(name, "discs/disc%d", dev->number);
devfs_find_and_unregister(NULL, name, 0, 0, 0, 0);
devfs_remove("discs/disc%d", dev->number);
if (!(dev->flags & GENHD_FL_DEVFS)) {
devfs_unregister(dev->de);
dev->de = NULL;
......
......@@ -39,6 +39,8 @@
typedef struct devfs_entry * devfs_handle_t;
extern void devfs_remove(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
#ifdef CONFIG_DEVFS_FS
struct unique_numspace
......@@ -159,6 +161,9 @@ static inline void devfs_find_and_unregister (devfs_handle_t dir,
char type, int traverse_symlinks)
{
}
static inline void devfs_remove(const char *fmt, ...)
{
}
static inline int devfs_get_flags (devfs_handle_t de, unsigned int *flags)
{
return 0;
......
......@@ -965,20 +965,12 @@ snd_info_entry_t *snd_info_create_device(const char *name, unsigned int number,
void snd_info_free_device(snd_info_entry_t * entry)
{
#ifdef CONFIG_DEVFS_FS
char dname[32];
#endif
snd_runtime_check(entry, return);
down(&info_mutex);
snd_remove_proc_entry(snd_proc_dev, entry->p);
up(&info_mutex);
#ifdef CONFIG_DEVFS_FS
if (entry->p && strncmp(entry->name, "controlC", 8)) {
sprintf(dname, "snd/%s", entry->name);
devfs_find_and_unregister(NULL, dname, 0, 0, DEVFS_SPECIAL_CHR, 0);
}
#endif
if (entry->p && strncmp(entry->name, "controlC", 8))
devfs_remove("snd/%s", entry->name);
snd_info_free_entry(entry);
}
......
......@@ -351,16 +351,11 @@ static int __init alsa_sound_init(void)
static void __exit alsa_sound_exit(void)
{
#ifdef CONFIG_DEVFS_FS
char controlname[24];
short controlnum;
for (controlnum = 0; controlnum < cards_limit; controlnum++) {
sprintf(controlname, "snd/controlC%d", controlnum);
devfs_find_and_unregister(NULL, controlname, 0, 0, DEVFS_SPECIAL_CHR, 0);
}
#endif
for (controlnum = 0; controlnum < cards_limit; controlnum++)
devfs_remove("snd/controlC%d", controlnum);
#ifdef CONFIG_SND_OSSEMUL
snd_info_minor_unregister();
#endif
......
......@@ -542,38 +542,6 @@ static const struct {
&num_audiodevs},
};
static char *
soundcard_make_name(char *buf, char *name, int idx) {
if (idx==0)
sprintf(buf, "sound/%s", name);
else
sprintf(buf, "sound/%s%d", name, idx);
return buf;
}
/* Register/unregister audio entries */
static void soundcard_register_devfs (int do_register)
{
char name_buf[32];
int i, j, num;
for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
num = (dev_list[i].num == NULL) ? 0 : *dev_list[i].num;
for (j = 0; j < num || j == 0; j++) {
soundcard_make_name (name_buf, dev_list[i].name, j);
if (do_register)
devfs_register (NULL, name_buf, DEVFS_FL_NONE,
SOUND_MAJOR, dev_list[i].minor+ (j* 0x10),
S_IFCHR | dev_list[i].mode,
&oss_sound_fops, NULL);
else
devfs_find_and_unregister(NULL, name_buf, 0, 0,
DEVFS_SPECIAL_CHR,0);
}
}
}
static int dmabuf = 0;
static int dmabug = 0;
......@@ -583,6 +551,8 @@ MODULE_PARM(dmabug, "i");
static int __init oss_init(void)
{
int err;
char name_buf[32];
int i, j;
/* drag in sound_syms.o */
{
......@@ -604,7 +574,22 @@ static int __init oss_init(void)
/* Protecting the innocent */
sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
soundcard_register_devfs(1);
for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
sprintf(name_buf, "sound/%s", dev_list[i].name);
devfs_register (NULL, name_buf, DEVFS_FL_NONE,
SOUND_MAJOR, dev_list[i].minor,
S_IFCHR | dev_list[i].mode,
&oss_sound_fops, NULL);
if (!dev_list[i].num)
continue;
for (j = 1; j < *dev_list[i].num; j++) {
sprintf(name_buf, "sound/%s%d", dev_list[i].name, j);
devfs_register (NULL, name_buf, DEVFS_FL_NONE,
SOUND_MAJOR, dev_list[i].minor + (j * 0x10),
S_IFCHR | dev_list[i].mode,
&oss_sound_fops, NULL);
}
}
if (sound_nblocks >= 1024)
printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");
......@@ -614,12 +599,18 @@ static int __init oss_init(void)
static void __exit oss_cleanup(void)
{
int i;
int i, j;
if (MOD_IN_USE)
return;
soundcard_register_devfs (0);
for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
devfs_remove("snd/%s", dev_list[i].name);
if (!dev_list[i].num)
continue;
for (j = 1; j < *dev_list[i].num; j++)
devfs_remove("sound/%s%d", dev_list[i].name, j);
}
unregister_sound_special(1);
unregister_sound_special(8);
......
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