Commit 3c8b5914 authored by Martin Diehl's avatar Martin Diehl Committed by Stephen Hemminger

[PATCH] fix vlsi_ir.c compile if !CONFIG_PROC_FS

On Mon, 9 Jun 2003, Jean Tourrilhes wrote:

> > Yes, Thanks. In fact walking over the proc-stuff in vlsi_ir, there are
> > some more places which need cleanup and fixing.
> >
> > Jean, please apply the patch below - ChangeLog:
>
> 	Would you mind sending it also to Jeff ? I want you to be able
> to work without depending on me.
> 	But I'll add that on my todo list anyway...

Ok - here we go. Slightly improved patch compared to what I've sent first
so we handle now failure in create_proc_entry and !CONFIG_PROC_FS
identical, i.e. continue without proc entry. It's not needed for the
driver to work.

Updated Changelog:

* make it compile without CONFIG_PROC_FS (problem reported by Adrian Bunk,
  original patch by Sam Ravnborg)
* get rid of a number of unneeded ifdef/endif CONFIG_PROC_FS (also
  removing an "unused label" warning)
* use proc entrys' owner fields to protect against module removal racing
  with proc entry access.
* handle failure in create_proc_entry like !CONFIG_PROC_FS
* set driver version 0.4a

Jeff, would please forward it for application to 2.5!

Martin
parent 189ea5d0
......@@ -2,7 +2,7 @@
*
* vlsi_ir.c: VLSI82C147 PCI IrDA controller driver for Linux
*
* Copyright (c) 2001-2002 Martin Diehl
* Copyright (c) 2001-2003 Martin Diehl
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -28,7 +28,7 @@ MODULE_AUTHOR("Martin Diehl <info@mdiehl.de>");
MODULE_LICENSE("GPL");
#define DRIVER_NAME "vlsi_ir"
#define DRIVER_VERSION "v0.4"
#define DRIVER_VERSION "v0.4a"
/********************************************************/
......@@ -149,6 +149,9 @@ static void vlsi_ring_debug(struct vlsi_ring *r)
/********************************************************/
/* needed regardless of CONFIG_PROC_FS */
static struct proc_dir_entry *vlsi_proc_root = NULL;
#ifdef CONFIG_PROC_FS
static int vlsi_proc_pdev(struct pci_dev *pdev, char *buf, int len)
......@@ -394,8 +397,6 @@ static int vlsi_proc_print(struct net_device *ndev, char *buf, int len)
return out - buf;
}
static struct proc_dir_entry *vlsi_proc_root = NULL;
struct vlsi_proc_data {
int size;
char *data;
......@@ -494,11 +495,18 @@ static int vlsi_proc_release(struct inode *inode, struct file *file)
}
static struct file_operations vlsi_proc_fops = {
/* protect individual procdir file entry against rmmod */
.owner = THIS_MODULE,
.open = vlsi_proc_open,
.llseek = vlsi_proc_lseek,
.read = vlsi_proc_read,
.release = vlsi_proc_release,
};
#define VLSI_PROC_FOPS (&vlsi_proc_fops)
#else /* CONFIG_PROC_FS */
#define VLSI_PROC_FOPS NULL
#endif
/********************************************************/
......@@ -1800,8 +1808,7 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto out_freedev;
}
#ifdef CONFIG_PROC_FS
{
if (vlsi_proc_root != NULL) {
struct proc_dir_entry *ent;
ent = create_proc_entry(ndev->name, S_IFREG|S_IRUGO, vlsi_proc_root);
......@@ -1810,11 +1817,11 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto out_unregister;
}
ent->data = ndev;
ent->proc_fops = &vlsi_proc_fops;
ent->proc_fops = VLSI_PROC_FOPS;
ent->size = 0;
idev->proc_entry = ent;
}
#endif
} else
idev->proc_entry = NULL;
printk(KERN_INFO "%s: registered device %s\n", drivername, ndev->name);
......@@ -1851,12 +1858,10 @@ static void __devexit vlsi_irda_remove(struct pci_dev *pdev)
down(&idev->sem);
pci_set_drvdata(pdev, NULL);
pci_disable_device(pdev);
#ifdef CONFIG_PROC_FS
if (idev->proc_entry) {
remove_proc_entry(ndev->name, vlsi_proc_root);
idev->proc_entry = NULL;
}
#endif
up(&idev->sem);
unregister_netdev(ndev);
......@@ -1993,9 +1998,7 @@ static struct pci_driver vlsi_irda_driver = {
#endif
};
#ifdef CONFIG_PROC_FS
#define PROC_DIR ("driver/" DRIVER_NAME)
#endif
static int __init vlsi_mod_init(void)
{
......@@ -2025,18 +2028,23 @@ static int __init vlsi_mod_init(void)
sirpulse = !!sirpulse;
#ifdef CONFIG_PROC_FS
/* create_proc_entry returns NULL if !CONFIG_PROC_FS.
* Failure to create the procfs entry is handled like running
* without procfs - it's not required for the driver to work.
*/
vlsi_proc_root = create_proc_entry(PROC_DIR, S_IFDIR, 0);
if (!vlsi_proc_root)
return -ENOMEM;
#endif
if (vlsi_proc_root) {
/* protect registered procdir against module removal.
* Because we are in the module init path there's no race
* window after create_proc_entry (and no barrier needed).
*/
vlsi_proc_root->owner = THIS_MODULE;
}
ret = pci_module_init(&vlsi_irda_driver);
#ifdef CONFIG_PROC_FS
if (ret)
if (ret && vlsi_proc_root)
remove_proc_entry(PROC_DIR, 0);
#endif
return ret;
}
......@@ -2044,6 +2052,7 @@ static int __init vlsi_mod_init(void)
static void __exit vlsi_mod_exit(void)
{
pci_unregister_driver(&vlsi_irda_driver);
if (vlsi_proc_root)
remove_proc_entry(PROC_DIR, 0);
}
......
......@@ -3,9 +3,9 @@
*
* vlsi_ir.h: VLSI82C147 PCI IrDA controller driver for Linux
*
* Version: 0.4
* Version: 0.4a
*
* Copyright (c) 2001-2002 Martin Diehl
* Copyright (c) 2001-2003 Martin Diehl
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -730,9 +730,7 @@ typedef struct vlsi_irda_dev {
u32 cfg_space[64/sizeof(u32)];
u8 resume_ok;
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *proc_entry;
#endif
} vlsi_irda_dev_t;
......
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