aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2006-06-26 03:25:54 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 12:58:25 -0400
commit8578cea7509cbdec25b31d08b48a92fcc3b1a9e3 (patch)
tree8de6c9bcd4108c3311fab9e66c3be5132e6f854d /fs
parent9cc8cbc7f8b7bc3db48bf6d59a731af728e786ce (diff)
[PATCH] proc: make PROC_NUMBUF the buffer size for holding integers as strings
Currently in /proc at several different places we define buffers to hold a process id, or a file descriptor . In most of them we use either a hard coded number or a different define. Modify them all to use PROC_NUMBUF, so the code has a chance of being maintained. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/proc/base.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index bbcaef9adb57..20746e124409 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -185,6 +185,9 @@ enum pid_directory_inos {
185 PROC_TID_FD_DIR = 0x8000, /* 0x8000-0xffff */ 185 PROC_TID_FD_DIR = 0x8000, /* 0x8000-0xffff */
186}; 186};
187 187
188/* Worst case buffer size needed for holding an integer. */
189#define PROC_NUMBUF 10
190
188struct pid_entry { 191struct pid_entry {
189 int type; 192 int type;
190 int len; 193 int len;
@@ -807,12 +810,12 @@ static ssize_t oom_adjust_read(struct file *file, char __user *buf,
807 size_t count, loff_t *ppos) 810 size_t count, loff_t *ppos)
808{ 811{
809 struct task_struct *task = proc_task(file->f_dentry->d_inode); 812 struct task_struct *task = proc_task(file->f_dentry->d_inode);
810 char buffer[8]; 813 char buffer[PROC_NUMBUF];
811 size_t len; 814 size_t len;
812 int oom_adjust = task->oomkilladj; 815 int oom_adjust = task->oomkilladj;
813 loff_t __ppos = *ppos; 816 loff_t __ppos = *ppos;
814 817
815 len = sprintf(buffer, "%i\n", oom_adjust); 818 len = snprintf(buffer, sizeof(buffer), "%i\n", oom_adjust);
816 if (__ppos >= len) 819 if (__ppos >= len)
817 return 0; 820 return 0;
818 if (count > len-__ppos) 821 if (count > len-__ppos)
@@ -827,14 +830,14 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
827 size_t count, loff_t *ppos) 830 size_t count, loff_t *ppos)
828{ 831{
829 struct task_struct *task = proc_task(file->f_dentry->d_inode); 832 struct task_struct *task = proc_task(file->f_dentry->d_inode);
830 char buffer[8], *end; 833 char buffer[PROC_NUMBUF], *end;
831 int oom_adjust; 834 int oom_adjust;
832 835
833 if (!capable(CAP_SYS_RESOURCE)) 836 if (!capable(CAP_SYS_RESOURCE))
834 return -EPERM; 837 return -EPERM;
835 memset(buffer, 0, 8); 838 memset(buffer, 0, sizeof(buffer));
836 if (count > 6) 839 if (count > sizeof(buffer) - 1)
837 count = 6; 840 count = sizeof(buffer) - 1;
838 if (copy_from_user(buffer, buf, count)) 841 if (copy_from_user(buffer, buf, count))
839 return -EFAULT; 842 return -EFAULT;
840 oom_adjust = simple_strtol(buffer, &end, 0); 843 oom_adjust = simple_strtol(buffer, &end, 0);
@@ -1099,8 +1102,6 @@ static struct inode_operations proc_pid_link_inode_operations = {
1099 .follow_link = proc_pid_follow_link 1102 .follow_link = proc_pid_follow_link
1100}; 1103};
1101 1104
1102#define NUMBUF 10
1103
1104static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir) 1105static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1105{ 1106{
1106 struct dentry *dentry = filp->f_dentry; 1107 struct dentry *dentry = filp->f_dentry;
@@ -1108,7 +1109,7 @@ static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1108 struct task_struct *p = proc_task(inode); 1109 struct task_struct *p = proc_task(inode);
1109 unsigned int fd, tid, ino; 1110 unsigned int fd, tid, ino;
1110 int retval; 1111 int retval;
1111 char buf[NUMBUF]; 1112 char buf[PROC_NUMBUF];
1112 struct files_struct * files; 1113 struct files_struct * files;
1113 struct fdtable *fdt; 1114 struct fdtable *fdt;
1114 1115
@@ -1144,7 +1145,7 @@ static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1144 continue; 1145 continue;
1145 rcu_read_unlock(); 1146 rcu_read_unlock();
1146 1147
1147 j = NUMBUF; 1148 j = PROC_NUMBUF;
1148 i = fd; 1149 i = fd;
1149 do { 1150 do {
1150 j--; 1151 j--;
@@ -1153,7 +1154,7 @@ static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1153 } while (i); 1154 } while (i);
1154 1155
1155 ino = fake_ino(tid, PROC_TID_FD_DIR + fd); 1156 ino = fake_ino(tid, PROC_TID_FD_DIR + fd);
1156 if (filldir(dirent, buf+j, NUMBUF-j, fd+2, ino, DT_LNK) < 0) { 1157 if (filldir(dirent, buf+j, PROC_NUMBUF-j, fd+2, ino, DT_LNK) < 0) {
1157 rcu_read_lock(); 1158 rcu_read_lock();
1158 break; 1159 break;
1159 } 1160 }
@@ -1828,14 +1829,14 @@ static struct inode_operations proc_tid_attr_inode_operations = {
1828static int proc_self_readlink(struct dentry *dentry, char __user *buffer, 1829static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
1829 int buflen) 1830 int buflen)
1830{ 1831{
1831 char tmp[30]; 1832 char tmp[PROC_NUMBUF];
1832 sprintf(tmp, "%d", current->tgid); 1833 sprintf(tmp, "%d", current->tgid);
1833 return vfs_readlink(dentry,buffer,buflen,tmp); 1834 return vfs_readlink(dentry,buffer,buflen,tmp);
1834} 1835}
1835 1836
1836static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd) 1837static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
1837{ 1838{
1838 char tmp[30]; 1839 char tmp[PROC_NUMBUF];
1839 sprintf(tmp, "%d", current->tgid); 1840 sprintf(tmp, "%d", current->tgid);
1840 return ERR_PTR(vfs_follow_link(nd,tmp)); 1841 return ERR_PTR(vfs_follow_link(nd,tmp));
1841} 1842}
@@ -1869,7 +1870,7 @@ static struct inode_operations proc_self_inode_operations = {
1869void proc_flush_task(struct task_struct *task) 1870void proc_flush_task(struct task_struct *task)
1870{ 1871{
1871 struct dentry *dentry, *leader, *dir; 1872 struct dentry *dentry, *leader, *dir;
1872 char buf[30]; 1873 char buf[PROC_NUMBUF];
1873 struct qstr name; 1874 struct qstr name;
1874 1875
1875 name.name = buf; 1876 name.name = buf;
@@ -2026,8 +2027,6 @@ out:
2026 return result; 2027 return result;
2027} 2028}
2028 2029
2029#define PROC_NUMBUF 10
2030
2031/* 2030/*
2032 * Find the first tgid to return to user space. 2031 * Find the first tgid to return to user space.
2033 * 2032 *