mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
firewire: cdev: refactor copy_to_user() in get_info ioctl call
A non-zero return value from copy_to_user() is handled by returning -EFAULT. Using scoped_guard() simplifies this handling, since it eliminates the need for a local variable to store the return value and check it after the locking primitive is released. Refactor the code to remove the local variable. Link: https://lore.kernel.org/r/20260920071501.77785-4-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This commit is contained in:
parent
19de2f11fc
commit
1f6877ccef
|
|
@ -491,7 +491,6 @@ union ioctl_arg {
|
|||
static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
|
||||
{
|
||||
struct fw_cdev_get_info *a = &arg->get_info;
|
||||
unsigned long ret = 0;
|
||||
|
||||
client->version = a->version;
|
||||
a->version = FW_CDEV_KERNEL_VERSION;
|
||||
|
|
@ -499,12 +498,10 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
|
|||
|
||||
scoped_guard(rwsem_read, &fw_device_rwsem) {
|
||||
if (a->rom != 0) {
|
||||
size_t want = a->rom_length;
|
||||
size_t have = client->device->config_rom_length * 4;
|
||||
size_t length = min_t(size_t, a->rom_length,
|
||||
client->device->config_rom_length * 4);
|
||||
|
||||
ret = copy_to_user(u64_to_uptr(a->rom), client->device->config_rom,
|
||||
min(want, have));
|
||||
if (ret != 0)
|
||||
if (copy_to_user(u64_to_uptr(a->rom), client->device->config_rom, length))
|
||||
return -EFAULT;
|
||||
}
|
||||
a->rom_length = client->device->config_rom_length * 4;
|
||||
|
|
@ -520,13 +517,15 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
|
|||
fill_bus_reset_event(&bus_reset, client);
|
||||
|
||||
/* unaligned size of bus_reset is 36 bytes */
|
||||
ret = copy_to_user(u64_to_uptr(a->bus_reset), &bus_reset, 36);
|
||||
if (copy_to_user(u64_to_uptr(a->bus_reset), &bus_reset, 36))
|
||||
return -EFAULT;
|
||||
}
|
||||
if (ret == 0 && list_empty(&client->link))
|
||||
|
||||
if (list_empty(&client->link))
|
||||
list_add_tail(&client->link, &client->device->client_list);
|
||||
}
|
||||
|
||||
return ret ? -EFAULT : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_client_resource(struct client *client, struct client_resource *resource,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user