提交 90926f0e 编写于 作者: J Jan Kiszka 提交者: David S. Miller

CAPI: Sanitize capifs API

Instead of looking up the dentry of an NCCI node again in
capifs_free_ncci pass the pointer via the capifs user.

This patch also reduces the #ifdef mess in capi.c a bit as far as capifs
was causing it.
Signed-off-by: NJan Kiszka <jan.kiszka@web.de>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 c947862f
...@@ -42,9 +42,8 @@ ...@@ -42,9 +42,8 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/isdn/capiutil.h> #include <linux/isdn/capiutil.h>
#include <linux/isdn/capicmd.h> #include <linux/isdn/capicmd.h>
#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
#include "capifs.h" #include "capifs.h"
#endif
static char *revision = "$Revision: 1.1.2.7 $"; static char *revision = "$Revision: 1.1.2.7 $";
...@@ -96,6 +95,7 @@ struct capiminor { ...@@ -96,6 +95,7 @@ struct capiminor {
struct list_head list; struct list_head list;
struct capincci *nccip; struct capincci *nccip;
unsigned int minor; unsigned int minor;
struct dentry *capifs_dentry;
struct capi20_appl *ap; struct capi20_appl *ap;
u32 ncci; u32 ncci;
...@@ -328,9 +328,9 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) ...@@ -328,9 +328,9 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
#ifdef _DEBUG_REFCOUNT #ifdef _DEBUG_REFCOUNT
printk(KERN_DEBUG "set mp->nccip\n"); printk(KERN_DEBUG "set mp->nccip\n");
#endif #endif
#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) mp->capifs_dentry =
capifs_new_ncci(mp->minor, MKDEV(capi_ttymajor, mp->minor)); capifs_new_ncci(mp->minor,
#endif MKDEV(capi_ttymajor, mp->minor));
} }
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
for (pp=&cdev->nccis; *pp; pp = &(*pp)->next) for (pp=&cdev->nccis; *pp; pp = &(*pp)->next)
...@@ -353,9 +353,7 @@ static void capincci_free(struct capidev *cdev, u32 ncci) ...@@ -353,9 +353,7 @@ static void capincci_free(struct capidev *cdev, u32 ncci)
*pp = (*pp)->next; *pp = (*pp)->next;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
if ((mp = np->minorp) != NULL) { if ((mp = np->minorp) != NULL) {
#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) capifs_free_ncci(mp->capifs_dentry);
capifs_free_ncci(mp->minor);
#endif
if (mp->tty) { if (mp->tty) {
mp->nccip = NULL; mp->nccip = NULL;
#ifdef _DEBUG_REFCOUNT #ifdef _DEBUG_REFCOUNT
......
...@@ -141,31 +141,32 @@ static struct file_system_type capifs_fs_type = { ...@@ -141,31 +141,32 @@ static struct file_system_type capifs_fs_type = {
.kill_sb = kill_anon_super, .kill_sb = kill_anon_super,
}; };
static struct dentry *get_node(int num) struct dentry *capifs_new_ncci(unsigned int number, dev_t device)
{
char s[10];
struct dentry *root = capifs_root;
mutex_lock(&root->d_inode->i_mutex);
return lookup_one_len(s, root, sprintf(s, "%d", num));
}
void capifs_new_ncci(unsigned int number, dev_t device)
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
char name[10];
int namelen;
dentry = get_node(number); mutex_lock(&capifs_root->d_inode->i_mutex);
if (IS_ERR(dentry))
namelen = sprintf(name, "%d", number);
dentry = lookup_one_len(name, capifs_root, namelen);
if (IS_ERR(dentry)) {
dentry = NULL;
goto unlock_out; goto unlock_out;
}
if (dentry->d_inode) { if (dentry->d_inode) {
dput(dentry); dput(dentry);
dentry = NULL;
goto unlock_out; goto unlock_out;
} }
inode = new_inode(capifs_mnt->mnt_sb); inode = new_inode(capifs_mnt->mnt_sb);
if (!inode) { if (!inode) {
dput(dentry); dput(dentry);
dentry = NULL;
goto unlock_out; goto unlock_out;
} }
...@@ -177,24 +178,31 @@ void capifs_new_ncci(unsigned int number, dev_t device) ...@@ -177,24 +178,31 @@ void capifs_new_ncci(unsigned int number, dev_t device)
init_special_inode(inode, S_IFCHR|config.mode, device); init_special_inode(inode, S_IFCHR|config.mode, device);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
dget(dentry);
unlock_out: unlock_out:
mutex_unlock(&capifs_root->d_inode->i_mutex); mutex_unlock(&capifs_root->d_inode->i_mutex);
return dentry;
} }
void capifs_free_ncci(unsigned int number) void capifs_free_ncci(struct dentry *dentry)
{ {
struct dentry *dentry = get_node(number); struct inode *inode;
if (!IS_ERR(dentry)) { if (!dentry)
struct inode *inode = dentry->d_inode; return;
if (inode) {
inode->i_nlink--; mutex_lock(&capifs_root->d_inode->i_mutex);
d_delete(dentry);
dput(dentry); inode = dentry->d_inode;
} if (inode) {
drop_nlink(inode);
d_delete(dentry);
dput(dentry); dput(dentry);
} }
dput(dentry);
mutex_unlock(&capifs_root->d_inode->i_mutex); mutex_unlock(&capifs_root->d_inode->i_mutex);
} }
......
...@@ -7,5 +7,22 @@ ...@@ -7,5 +7,22 @@
* *
*/ */
void capifs_new_ncci(unsigned int num, dev_t device); #include <linux/dcache.h>
void capifs_free_ncci(unsigned int num);
#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
struct dentry *capifs_new_ncci(unsigned int num, dev_t device);
void capifs_free_ncci(struct dentry *dentry);
#else
static inline struct dentry *capifs_new_ncci(unsigned int num, dev_t device)
{
return NULL;
}
static inline void capifs_free_ncci(struct dentry *dentry)
{
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册