Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Blackfin: cplbinfo: drop d_path() hacks

The cplbinfo was using d_path() to figure out which cpu/cplb was being
parsed. As Al pointed out, this isn't exactly reliable as it assumes the
static VFS path to be unchanged, and it's just poor form. So use the
proc_create_data() to properly (and internally) pass the exact cpu/cplb
requested to the parser function.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

+12 -13
+12 -13
arch/blackfin/kernel/cplbinfo.c
··· 112 112 .show = cplbinfo_show, 113 113 }; 114 114 115 + #define CPLBINFO_DCPLB_FLAG 0x80000000 116 + 115 117 static int cplbinfo_open(struct inode *inode, struct file *file) 116 118 { 117 - char buf[256], *path, *p; 119 + struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); 120 + char cplb_type; 118 121 unsigned int cpu; 119 - char *s_cpu, *s_cplb; 120 122 int ret; 121 123 struct seq_file *m; 122 124 struct cplbinfo_data *cdata; 123 125 124 - path = d_path(&file->f_path, buf, sizeof(buf)); 125 - if (IS_ERR(path)) 126 - return PTR_ERR(path); 127 - s_cpu = strstr(path, "/cpu"); 128 - s_cplb = strrchr(path, '/'); 129 - if (!s_cpu || !s_cplb) 130 - return -EINVAL; 126 + cpu = (unsigned int)pde->data; 127 + cplb_type = cpu & CPLBINFO_DCPLB_FLAG ? 'D' : 'I'; 128 + cpu &= ~CPLBINFO_DCPLB_FLAG; 131 129 132 - cpu = simple_strtoul(s_cpu + 4, &p, 10); 133 130 if (!cpu_online(cpu)) 134 131 return -ENODEV; 135 132 ··· 137 140 cdata = m->private; 138 141 139 142 cdata->pos = 0; 140 - cdata->cplb_type = toupper(s_cplb[1]); 143 + cdata->cplb_type = cplb_type; 141 144 cplbinfo_seq_init(cdata, cpu); 142 145 143 146 return 0; ··· 166 169 if (!cpu_dir) 167 170 return -ENOMEM; 168 171 169 - proc_create("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops); 170 - proc_create("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops); 172 + proc_create_data("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops, 173 + (void *)cpu); 174 + proc_create_data("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops, 175 + (void *)(cpu | CPLBINFO_DCPLB_FLAG)); 171 176 } 172 177 173 178 return 0;