staging: lustre: remove kmalloc from fld_proc_hash_seq_write
This patch simplifies the fld_proc_hash_seq_write function by removing the dynamic memory allocation. The longest fh_name used so far in lustre is 4 characters. We use a 8 bytes variable to be on the safe side. Signed-off-by: Tristan Lelong <tristan@lelong.xyz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
9ef6a83312
commit
41dff7ac1a
|
@ -93,17 +93,13 @@ fld_proc_hash_seq_write(struct file *file,
|
||||||
{
|
{
|
||||||
struct lu_client_fld *fld;
|
struct lu_client_fld *fld;
|
||||||
struct lu_fld_hash *hash = NULL;
|
struct lu_fld_hash *hash = NULL;
|
||||||
char *name;
|
char fh_name[8];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (count > 80)
|
if (count > sizeof(fh_name))
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
|
|
||||||
name = kmalloc(count, GFP_KERNEL);
|
if (copy_from_user(fh_name, buffer, count) != 0)
|
||||||
if (!name)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
if (copy_from_user(name, buffer, count) != 0)
|
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
fld = ((struct seq_file *)file->private_data)->private;
|
fld = ((struct seq_file *)file->private_data)->private;
|
||||||
|
@ -113,7 +109,7 @@ fld_proc_hash_seq_write(struct file *file,
|
||||||
if (count != strlen(fld_hash[i].fh_name))
|
if (count != strlen(fld_hash[i].fh_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!strncmp(fld_hash[i].fh_name, name, count)) {
|
if (!strncmp(fld_hash[i].fh_name, fh_name, count)) {
|
||||||
hash = &fld_hash[i];
|
hash = &fld_hash[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +124,6 @@ fld_proc_hash_seq_write(struct file *file,
|
||||||
fld->lcf_name, hash->fh_name);
|
fld->lcf_name, hash->fh_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(name);
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue