Using snprintf() for show() methods holds the risk of buffer overrun as snprintf() does not know the PAGE_SIZE maximum of the temporary buffer used to output sysfs content. This patchset is a series of Coccinelle cleanups across the staging directory to convert snprintf with scnprintf in the relevant files. Sumera Priyadarsini (5): gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Using snprintf() for show() methods holds the risk of buffer overrun as snprintf() does not know the PAGE_SIZE maximum of the temporary buffer used to output sysfs content. Modify amdgpu_atombios.c to use sysfs_emit() instead which knows the size of the temporary buffer. Issue found with Coccinelle. Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c index 469352e2d6ec..3c19862c94c7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c @@ -1947,7 +1947,7 @@ static ssize_t amdgpu_atombios_get_vbios_version(struct device *dev, struct amdgpu_device *adev = drm_to_adev(ddev); struct atom_context *ctx = adev->mode_info.atom_context; - return snprintf(buf, PAGE_SIZE, "%s\n", ctx->vbios_version); + return sysfs_emit(buf, PAGE_SIZE, "%s\n", ctx->vbios_version); } static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version, -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Using snprintf() for show() methods holds the risk of buffer overrun as snprintf() does not know the PAGE_SIZE maximum of the temporary buffer used to output sysfs content. Modify amdgpu_device.c to use sysfs_emit() instead which knows the size of the temporary buffer. Issue found with Coccinelle. Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index f7307af76452..7eef6b20578f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -135,7 +135,7 @@ static ssize_t amdgpu_device_get_pcie_replay_count(struct device *dev, struct amdgpu_device *adev = drm_to_adev(ddev); uint64_t cnt = amdgpu_asic_get_pcie_replay_count(adev); - return snprintf(buf, PAGE_SIZE, "%llu\n", cnt); + return sysfs_emit(buf, PAGE_SIZE, "%llu\n", cnt); } static DEVICE_ATTR(pcie_replay_count, S_IRUGO, @@ -159,7 +159,7 @@ static ssize_t amdgpu_device_get_product_name(struct device *dev, struct drm_device *ddev = dev_get_drvdata(dev); struct amdgpu_device *adev = drm_to_adev(ddev); - return snprintf(buf, PAGE_SIZE, "%s\n", adev->product_name); + return sysfs_emit(buf, PAGE_SIZE, "%s\n", adev->product_name); } static DEVICE_ATTR(product_name, S_IRUGO, @@ -181,7 +181,7 @@ static ssize_t amdgpu_device_get_product_number(struct device *dev, struct drm_device *ddev = dev_get_drvdata(dev); struct amdgpu_device *adev = drm_to_adev(ddev); - return snprintf(buf, PAGE_SIZE, "%s\n", adev->product_number); + return sysfs_emit(buf, PAGE_SIZE, "%s\n", adev->product_number); } static DEVICE_ATTR(product_number, S_IRUGO, @@ -203,7 +203,7 @@ static ssize_t amdgpu_device_get_serial_number(struct device *dev, struct drm_device *ddev = dev_get_drvdata(dev); struct amdgpu_device *adev = drm_to_adev(ddev); - return snprintf(buf, PAGE_SIZE, "%s\n", adev->serial); + return sysfs_emit(buf, PAGE_SIZE, "%s\n", adev->serial); } static DEVICE_ATTR(serial_number, S_IRUGO, -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Using snprintf() for show() methods holds the risk of buffer overrun as snprintf() does not know the PAGE_SIZE maximum of the temporary buffer used to output sysfs content. Modify amdgpu_gtt_mgr.c to use sysfs_emit() instead which knows the size of the temporary buffer. Issue found with Coccinelle. Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c index 1721739def84..441e07ee1967 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c @@ -49,7 +49,7 @@ static ssize_t amdgpu_mem_info_gtt_total_show(struct device *dev, struct amdgpu_device *adev = drm_to_adev(ddev); struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT); - return snprintf(buf, PAGE_SIZE, "%llu\n", + return sysfs_emit(buf, PAGE_SIZE, "%llu\n", man->size * PAGE_SIZE); } @@ -68,7 +68,7 @@ static ssize_t amdgpu_mem_info_gtt_used_show(struct device *dev, struct amdgpu_device *adev = drm_to_adev(ddev); struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT); - return snprintf(buf, PAGE_SIZE, "%llu\n", + return sysfs_emit(buf, PAGE_SIZE, "%llu\n", amdgpu_gtt_mgr_usage(man)); } -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Using snprintf() for show() methods holds the risk of buffer overrun as snprintf() does not know the PAGE_SIZE maximum of the temporary buffer used to output sysfs content. Modify amdgpu_psp.c to use sysfs_emit() instead which knows the size of the temporary buffer. Issue found with Coccinelle. Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c index d6c38e24f130..4d1d1e1b005d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c @@ -2621,7 +2621,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_read(struct device *dev, return ret; } - return snprintf(buf, PAGE_SIZE, "%x\n", fw_ver); + return sysfs_emit(buf, PAGE_SIZE, "%x\n", fw_ver); } static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev, -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Using snprintf() for show() methods holds the risk of buffer overrun as snprintf() does not know the PAGE_SIZE maximum of the temporary buffer used to output sysfs content. Modify amdgpu_ras.c to use sysfs_emit() instead which knows the size of the temporary buffer. Issue found with Coccinelle. Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c index e5ea14774c0c..6d9901e1b4b0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -429,13 +429,13 @@ static ssize_t amdgpu_ras_sysfs_read(struct device *dev, }; if (!amdgpu_ras_get_error_query_ready(obj->adev)) - return snprintf(buf, PAGE_SIZE, + return sysfs_emit(buf, PAGE_SIZE, "Query currently inaccessible\n"); if (amdgpu_ras_error_query(obj->adev, &info)) return -EINVAL; - return snprintf(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n", + return sysfs_emit(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n", "ue", info.ue_count, "ce", info.ce_count); } -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
On Thu, Oct 22, 2020 at 07:17:56PM +0530, Sumera Priyadarsini wrote: > Using snprintf() for show() methods holds the risk of buffer overrun > as snprintf() does not know the PAGE_SIZE maximum of the temporary > buffer used to output sysfs content. > > Modify amdgpu_psp.c to use sysfs_emit() instead which knows the > size of the temporary buffer. > > Issue found with Coccinelle. > > Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c > index d6c38e24f130..4d1d1e1b005d 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c > @@ -2621,7 +2621,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_read(struct device *dev, > return ret; > } > > - return snprintf(buf, PAGE_SIZE, "%x\n", fw_ver); > + return sysfs_emit(buf, PAGE_SIZE, "%x\n", fw_ver); Did you build this code? I don't think it is correct... thanks, greg k-h _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
On Thu, Oct 22, 2020 at 07:07:50PM +0530, Sumera Priyadarsini wrote: > Using snprintf() for show() methods holds the risk of buffer overrun > as snprintf() does not know the PAGE_SIZE maximum of the temporary > buffer used to output sysfs content. > > This patchset is a series of Coccinelle cleanups across the staging > directory to convert snprintf with scnprintf in the relevant files. I think you need to edit your template here since this is now drivers/gpu, not staging :-) -Daniel > > Sumera Priyadarsini (5): > gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() > gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() > gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() > gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() > gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() > > drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++---- > drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 4 ++-- > drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++-- > 5 files changed, 10 insertions(+), 10 deletions(-) > > -- > 2.25.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[-- Attachment #1.1: Type: text/plain, Size: 1484 bytes --] On Thu, Oct 22, 2020 at 7:24 PM Greg KH <gregkh@linuxfoundation.org> wrote: > On Thu, Oct 22, 2020 at 07:17:56PM +0530, Sumera Priyadarsini wrote: > > Using snprintf() for show() methods holds the risk of buffer overrun > > as snprintf() does not know the PAGE_SIZE maximum of the temporary > > buffer used to output sysfs content. > > > > Modify amdgpu_psp.c to use sysfs_emit() instead which knows the > > size of the temporary buffer. > > > > Issue found with Coccinelle. > > > > Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com> > > --- > > drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c > > index d6c38e24f130..4d1d1e1b005d 100644 > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c > > @@ -2621,7 +2621,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_read(struct > device *dev, > > return ret; > > } > > > > - return snprintf(buf, PAGE_SIZE, "%x\n", fw_ver); > > + return sysfs_emit(buf, PAGE_SIZE, "%x\n", fw_ver); > > Did you build this code? I don't think it is correct... > Yes, you are right. I compiled all of them again separately. I had based them off the usual drm tree but that is wrong because sysfs_emit has been added only in the 5.10. I will send a v2 with the proper corrections. regards, sumera > thanks, > > greg k-h > [-- Attachment #1.2: Type: text/html, Size: 2303 bytes --] [-- Attachment #2: Type: text/plain, Size: 154 bytes --] _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx