[PATCH 0/3] firewire: fix minor issues
Hi,
This patchset includes below patches posted by several developers.
* [PATCH v2] firewire: convert sysfs sprintf/snprintf family to sysfs_emit * https://lore.kernel.org/lkml/1612424420-96871-1-git-send-email-jiapeng.chong... * [PATCH V2] drivers/firewire: use struct_size over open coded arithmetic * https://lore.kernel.org/lkml/20220210060805.1608198-1-chi.minghao@zte.com.cn... * [PATCH] firewire: Fix using uninitialized value * https://lore.kernel.org/lkml/20220411105205.2520784-1-lv.ruyi@zte.com.cn/
They are for some minor issues, while preferable. I expect the patches are going to be sent to Linus for next merge window by maintainer of either Linux FireWire subsystem or sound subsystem.
Regards
Jiapeng Chong (1): firewire: convert sysfs sprintf/snprintf family to sysfs_emit
Lv Ruyi (1): firewire: Fix using uninitialized value
Minghao Chi (CGEL ZTE) (1): firewire: use struct_size over open coded arithmetic
drivers/firewire/core-device.c | 6 ++---- drivers/firewire/core-transaction.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
From: Jiapeng Chong jiapeng.chong@linux.alibaba.com
Fix the following coccicheck warning:
./drivers/firewire/core-device.c:375:8-16: WARNING: use scnprintf or sprintf.
Reported-by: Abaci Robotabaci@linux.alibaba.com Signed-off-by: Jiapeng Chong jiapeng.chong@linux.alibaba.com Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- drivers/firewire/core-device.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 90ed8fdaba75..adddd8c45d0c 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -372,8 +372,7 @@ static ssize_t rom_index_show(struct device *dev, struct fw_device *device = fw_device(dev->parent); struct fw_unit *unit = fw_unit(dev);
- return snprintf(buf, PAGE_SIZE, "%d\n", - (int)(unit->directory - device->config_rom)); + return sysfs_emit(buf, "%td\n", unit->directory - device->config_rom); }
static struct device_attribute fw_unit_attributes[] = { @@ -403,8 +402,7 @@ static ssize_t guid_show(struct device *dev, int ret;
down_read(&fw_device_rwsem); - ret = snprintf(buf, PAGE_SIZE, "0x%08x%08x\n", - device->config_rom[3], device->config_rom[4]); + ret = sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->config_rom[4]); up_read(&fw_device_rwsem);
return ret;
From: "Minghao Chi (CGEL ZTE)" chi.minghao@zte.com.cn
Replace zero-length array with flexible-array member and make use of the struct_size() helper in kmalloc(). For example:
struct fw_request { ... u32 data[]; }
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes.
Signed-off-by: Minghao Chi (CGEL ZTE) chi.minghao@zte.com.cn Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- drivers/firewire/core-transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index e12a0a4c33f7..49657a793e80 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -778,7 +778,7 @@ static struct fw_request *allocate_request(struct fw_card *card, return NULL; }
- request = kmalloc(sizeof(*request) + length, GFP_ATOMIC); + request = kmalloc(struct_size(request, data, length), GFP_ATOMIC); if (request == NULL) return NULL;
From: Lv Ruyi lv.ruyi@zte.com.cn
If data is null, request->data wouldn't be assigned value. It is random value, but we use it in handle_exclusive_region_request() and handle_fcp_region_request() later. Fix the bug by initializing it.
(Revised by Takashi Sakamoto to rebase to the previous patch.)
Reported-by: Zeal Robot zealci@zte.com.cn Signed-off-by: Lv Ruyi lv.ruyi@zte.com.cn Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- drivers/firewire/core-transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index 49657a793e80..d10d890d7d48 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -778,7 +778,7 @@ static struct fw_request *allocate_request(struct fw_card *card, return NULL; }
- request = kmalloc(struct_size(request, data, length), GFP_ATOMIC); + request = kzalloc(struct_size(request, data, length), GFP_ATOMIC); if (request == NULL) return NULL;
participants (1)
-
Takashi Sakamoto