mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
scsi: proc: Use kmalloc() in proc writers
proc_scsi_host_write(), proc_scsi_write() and proc_scsi_devinfo_write() allocate temporary buffers for /proc writes using __get_free_page(). These buffers can be allocated with kmalloc() as there's nothing special about them to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Replace use of __get_free_page() with kmalloc(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Reviewed-by: Hannes Reinecke <hare@kernel.org> Reviewed-by: John Garry <john.g.garry@oracle.com> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Link: https://patch.msgid.link/20260704-b4-scsi-v2-2-7d2d21a810de@kernel.org Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
This commit is contained in:
parent
f07ed52723
commit
b4fe0d7d41
|
|
@ -691,7 +691,8 @@ static ssize_t proc_scsi_devinfo_write(struct file *file,
|
|||
|
||||
if (!buf || length>PAGE_SIZE)
|
||||
return -EINVAL;
|
||||
if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
|
||||
buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
if (copy_from_user(buffer, buf, length)) {
|
||||
err =-EFAULT;
|
||||
|
|
@ -708,7 +709,7 @@ static ssize_t proc_scsi_devinfo_write(struct file *file,
|
|||
scsi_dev_info_list_add_str(buffer);
|
||||
|
||||
out:
|
||||
free_page((unsigned long)buffer);
|
||||
kfree(buffer);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <linux/mutex.h>
|
||||
#include <linux/gfp.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include <scsi/scsi.h>
|
||||
#include <scsi/scsi_device.h>
|
||||
|
|
@ -74,7 +75,7 @@ static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
|
|||
if (!shost->hostt->write_info)
|
||||
return -EINVAL;
|
||||
|
||||
page = (char *)__get_free_page(GFP_KERNEL);
|
||||
page = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||
if (page) {
|
||||
ret = -EFAULT;
|
||||
if (copy_from_user(page, buf, count))
|
||||
|
|
@ -82,7 +83,7 @@ static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
|
|||
ret = shost->hostt->write_info(shost, page, count);
|
||||
}
|
||||
out:
|
||||
free_page((unsigned long)page);
|
||||
kfree(page);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -412,7 +413,7 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
|
|||
if (!buf || length > PAGE_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
buffer = (char *)__get_free_page(GFP_KERNEL);
|
||||
buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
@ -467,7 +468,7 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
|
|||
err = length;
|
||||
|
||||
out:
|
||||
free_page((unsigned long)buffer);
|
||||
kfree(buffer);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user