Commit 4d8e8d21 authored by Al Viro's avatar Al Viro

hysdn: stash pointer to card into proc_dir_entry->data

no need to search later - we know the card when we are
creating procfs entries
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 03b642a7
...@@ -229,23 +229,12 @@ static int ...@@ -229,23 +229,12 @@ static int
hysdn_conf_open(struct inode *ino, struct file *filep) hysdn_conf_open(struct inode *ino, struct file *filep)
{ {
hysdn_card *card; hysdn_card *card;
struct proc_dir_entry *pd;
struct conf_writedata *cnf; struct conf_writedata *cnf;
char *cp, *tmp; char *cp, *tmp;
/* now search the addressed card */ /* now search the addressed card */
mutex_lock(&hysdn_conf_mutex); mutex_lock(&hysdn_conf_mutex);
card = card_root; card = PDE(ino)->data;
while (card) {
pd = card->procconf;
if (pd == PDE(ino))
break;
card = card->next; /* search next entry */
}
if (!card) {
mutex_unlock(&hysdn_conf_mutex);
return (-ENODEV); /* device is unknown/invalid */
}
if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x", hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x",
filep->f_cred->fsuid, filep->f_cred->fsgid, filep->f_cred->fsuid, filep->f_cred->fsgid,
...@@ -317,21 +306,9 @@ hysdn_conf_close(struct inode *ino, struct file *filep) ...@@ -317,21 +306,9 @@ hysdn_conf_close(struct inode *ino, struct file *filep)
hysdn_card *card; hysdn_card *card;
struct conf_writedata *cnf; struct conf_writedata *cnf;
int retval = 0; int retval = 0;
struct proc_dir_entry *pd;
mutex_lock(&hysdn_conf_mutex); mutex_lock(&hysdn_conf_mutex);
/* search the addressed card */ card = PDE(ino)->data;
card = card_root;
while (card) {
pd = card->procconf;
if (pd == PDE(ino))
break;
card = card->next; /* search next entry */
}
if (!card) {
mutex_unlock(&hysdn_conf_mutex);
return (-ENODEV); /* device is unknown/invalid */
}
if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
hysdn_addlog(card, "config close for uid=%d gid=%d mode=0x%x", hysdn_addlog(card, "config close for uid=%d gid=%d mode=0x%x",
filep->f_cred->fsuid, filep->f_cred->fsgid, filep->f_cred->fsuid, filep->f_cred->fsgid,
...@@ -394,10 +371,11 @@ hysdn_procconf_init(void) ...@@ -394,10 +371,11 @@ hysdn_procconf_init(void)
while (card) { while (card) {
sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid); sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid);
if ((card->procconf = (void *) proc_create(conf_name, if ((card->procconf = (void *) proc_create_data(conf_name,
S_IFREG | S_IRUGO | S_IWUSR, S_IFREG | S_IRUGO | S_IWUSR,
hysdn_proc_entry, hysdn_proc_entry,
&conf_fops)) != NULL) { &conf_fops,
card)) != NULL) {
hysdn_proclog_init(card); /* init the log file entry */ hysdn_proclog_init(card); /* init the log file entry */
} }
card = card->next; /* next entry */ card = card->next; /* next entry */
......
...@@ -173,27 +173,14 @@ hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t *off) ...@@ -173,27 +173,14 @@ hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t *off)
{ {
struct log_data *inf; struct log_data *inf;
int len; int len;
struct proc_dir_entry *pde = PDE(file_inode(file)); hysdn_card *card = PDE(file_inode(file))->data;
struct procdata *pd = NULL;
hysdn_card *card;
if (!*((struct log_data **) file->private_data)) { if (!*((struct log_data **) file->private_data)) {
struct procdata *pd = card->proclog;
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
return (-EAGAIN); return (-EAGAIN);
/* sorry, but we need to search the card */
card = card_root;
while (card) {
pd = card->proclog;
if (pd->log == pde)
break;
card = card->next; /* search next entry */
}
if (card)
interruptible_sleep_on(&(pd->rd_queue)); interruptible_sleep_on(&(pd->rd_queue));
else
return (-EAGAIN);
} }
if (!(inf = *((struct log_data **) file->private_data))) if (!(inf = *((struct log_data **) file->private_data)))
return (0); return (0);
...@@ -215,27 +202,15 @@ hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t *off) ...@@ -215,27 +202,15 @@ hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t *off)
static int static int
hysdn_log_open(struct inode *ino, struct file *filep) hysdn_log_open(struct inode *ino, struct file *filep)
{ {
hysdn_card *card; hysdn_card *card = PDE(ino)->data;
struct procdata *pd = NULL;
unsigned long flags;
mutex_lock(&hysdn_log_mutex); mutex_lock(&hysdn_log_mutex);
card = card_root;
while (card) {
pd = card->proclog;
if (pd->log == PDE(ino))
break;
card = card->next; /* search next entry */
}
if (!card) {
mutex_unlock(&hysdn_log_mutex);
return (-ENODEV); /* device is unknown/invalid */
}
filep->private_data = card; /* remember our own card */
if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
/* write only access -> write log level only */ /* write only access -> write log level only */
filep->private_data = card; /* remember our own card */
} else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
struct procdata *pd = card->proclog;
unsigned long flags;
/* read access -> log/debug read */ /* read access -> log/debug read */
spin_lock_irqsave(&card->hysdn_lock, flags); spin_lock_irqsave(&card->hysdn_lock, flags);
...@@ -275,20 +250,12 @@ hysdn_log_close(struct inode *ino, struct file *filep) ...@@ -275,20 +250,12 @@ hysdn_log_close(struct inode *ino, struct file *filep)
} else { } else {
/* read access -> log/debug read, mark one further file as closed */ /* read access -> log/debug read, mark one further file as closed */
pd = NULL;
inf = *((struct log_data **) filep->private_data); /* get first log entry */ inf = *((struct log_data **) filep->private_data); /* get first log entry */
if (inf) if (inf)
pd = (struct procdata *) inf->proc_ctrl; /* still entries there */ pd = (struct procdata *) inf->proc_ctrl; /* still entries there */
else { else {
/* no info available -> search card */ /* no info available -> search card */
card = card_root; card = PDE(file_inode(filep))->data;
while (card) {
pd = card->proclog;
if (pd->log == PDE(ino))
break;
card = card->next; /* search next entry */
}
if (card)
pd = card->proclog; /* pointer to procfs log */ pd = card->proclog; /* pointer to procfs log */
} }
if (pd) if (pd)
...@@ -319,24 +286,12 @@ static unsigned int ...@@ -319,24 +286,12 @@ static unsigned int
hysdn_log_poll(struct file *file, poll_table *wait) hysdn_log_poll(struct file *file, poll_table *wait)
{ {
unsigned int mask = 0; unsigned int mask = 0;
struct proc_dir_entry *pde = PDE(file_inode(file)); hysdn_card *card = PDE(file_inode(file))->data;
hysdn_card *card; struct procdata *pd = card->proclog;
struct procdata *pd = NULL;
if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE)
return (mask); /* no polling for write supported */ return (mask); /* no polling for write supported */
/* we need to search the card */
card = card_root;
while (card) {
pd = card->proclog;
if (pd->log == pde)
break;
card = card->next; /* search next entry */
}
if (!card)
return (mask); /* card not found */
poll_wait(file, &(pd->rd_queue), wait); poll_wait(file, &(pd->rd_queue), wait);
if (*((struct log_data **) file->private_data)) if (*((struct log_data **) file->private_data))
...@@ -373,9 +328,9 @@ hysdn_proclog_init(hysdn_card *card) ...@@ -373,9 +328,9 @@ hysdn_proclog_init(hysdn_card *card)
if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) { if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) {
sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid); sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid);
pd->log = proc_create(pd->log_name, pd->log = proc_create_data(pd->log_name,
S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry, S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry,
&log_fops); &log_fops, card);
init_waitqueue_head(&(pd->rd_queue)); init_waitqueue_head(&(pd->rd_queue));
......
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