drm/amdgpu: Replace snprintf() with sysfs_emit
Subsystems (3)
cover drm/amdgpu: Replace snprintf() with sysfs_emit
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(-)
Signature · 1 line
2.25.1
Quoted 14 lines · Sumera Priyadarsini
Using
snprintf()forshow()methods holds the risk of buffer overrun assnprintf()does not know thePAGE_SIZEmaximum 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: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
Quoted 5 lines
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 ++--
These files are ot "in the staging directory" as your text above states :(
Also, you have 5 patches that do different things, yet have the same exact subject line, which isn't acceptable either.
thanks,
greg k-h
PATCH 1/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
In reply to Sumera PriyadarsiniUsing 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +1 -1
@@ -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,
Signature · 1 line
2.25.1
PATCH 2/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
In reply to Sumera PriyadarsiniUsing 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -4
@@ -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,
Signature · 1 line
2.25.1
PATCH 3/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
In reply to Sumera PriyadarsiniUsing 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +2 -2
@@ -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)); }
Signature · 1 line
2.25.1
PATCH 4/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
In reply to Sumera PriyadarsiniUsing 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -1
@@ -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,
Signature · 1 line
2.25.1
Quoted 16 lines · Greg KH
Quoted 14 lines · Sumera Priyadarsini
Using
snprintf()forshow()methods holds the risk of buffer overrun assnprintf()does not know thePAGE_SIZEmaximum 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: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
Quoted 7 lines
Quoted 5 lines
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 ++--These files are ot "in the staging directory" as your text above states :(
I think Sumera has sent it as part of the DRM project related task(s). So CC'ing outreachy-kernel mailing list is fine. Although I see 2 cover letters being sent - one with all mailing lists and maintainers being CC'ed and other one without most of them which is confusing.
Sumera: You may want to fix that.
Quoted 11 lines
Also, you have 5 patches that do different things, yet have the same exact subject line, which isn't acceptable either.
thanks,
greg k-h
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20201022133722.GA1784385%40kroah.com.
Signature · 5 lines
Vaishali -- Vaishali
PATCH 5/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
In reply to Sumera PriyadarsiniUsing 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -2
@@ -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); }
Signature · 1 line
2.25.1
Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
In reply to Sumera PriyadarsiniQuoted 19 lines · Sumera Priyadarsini
Using
snprintf()forshow()methods holds the risk of buffer overrun assnprintf()does not know thePAGE_SIZEmaximum of the temporary buffer used to output sysfs content.Modify
amdgpu_psp.cto usesysfs_emit()instead which knows the size of the temporary buffer.Issue found with Coccinelle.
Signed-off-by Sumera Priyadarsini <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static ssize_t psp_usbc_pd_fw_sysfs_read(struct device *dev, · line 2624
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-1@@ -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
Quoted 24 lines · Vaishali Thakkar,
Quoted 22 lines · Greg KH
Quoted 19 lines · Sumera Priyadarsini
Using
snprintf()forshow()methods holds the risk of buffer overrun assnprintf()does not know thePAGE_SIZEmaximum 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: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_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 ++--
Quoted 5 lines
Quoted 1 line
These files are ot "in the staging directory" as your text above states
:(
I think Sumera has sent it as part of the DRM project related task(s).
Yes, although I think Greg is referring to the cover letter text here- I will change that.
So CC'ing outreachy-kernel mailing list
Quoted 6 lines
is fine. Although I see 2 cover letters being sent - one with all mailing lists and maintainers being CC'ed and other one without most of them which is confusing.
Sumera: You may want to fix that.
I will send a v2 fixing the patchset.
regards,
Sumera
Quoted 25 lines
Also, you have 5 patches that do different things, yet have the same
Quoted 8 lines
exact subject line, which isn't acceptable either.
thanks,
greg k-h
--
You received this message because you are subscribed to the GoogleGroups "outreachy-kernel" group.
Quoted 1 line
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
Quoted 1 line
To view this discussion on the web visit
https://groups.google.com/d/msgid/outreachy-kernel/20201022133722.GA1784385%40kroah.com
.--
Vaishali--
Vaishali
Quoted 6 lines · Sumera Priyadarsini
Using
snprintf()forshow()methods holds the risk of buffer overrun assnprintf()does not know thePAGE_SIZEmaximum 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
Quoted 18 lines
Sumera Priyadarsini (5):
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_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(-)Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 28 lines · Sumera Priyadarsini
Quoted 24 lines · Vaishali Thakkar,
Quoted 22 lines · Greg KH
Quoted 19 lines · Sumera Priyadarsini
Using
snprintf()forshow()methods holds the risk of buffer overrun assnprintf()does not know thePAGE_SIZEmaximum 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: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_emit()
gpu: drm: amdgpu: Replacesnprintf()withsysfs_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 ++--
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
These files are ot "in the staging directory" as your text above states :(
I think Sumera has sent it as part of the DRM project related task(s).
Yes, although I think Greg is referring to the cover letter text here- I will change that.
Ouch, that's right! Missed that. :(
Quoted 38 lines
Quoted 6 lines
So CC'ing outreachy-kernel mailing list
is fine. Although I see 2 cover letters being sent - one with all mailing lists and maintainers being CC'ed and other one without most of them which is confusing.Sumera: You may want to fix that.
I will send a v2 fixing the patchset.
regards,
SumeraQuoted 14 lines
Quoted 11 lines
Also, you have 5 patches that do different things, yet have the same exact subject line, which isn't acceptable either.
thanks,
greg k-h
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20201022133722.GA1784385%40kroah.com.Quoted 6 lines
--
Vaishali--
Vaishali--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CACAkLuoubwnXBEHGry9kLy_YStwXu9bR%3DdGndt0Dx6JdJM%2B8LQ%40mail.gmail.com.
Signature · 1 line
Vaishali
Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
In reply to Greg KHQuoted 22 lines · Greg KH
Quoted 7 lines · Sumera Priyadarsini
Using
snprintf()forshow()methods holds the risk of buffer overrun assnprintf()does not know thePAGE_SIZEmaximum of the temporary buffer used to output sysfs content.Modify
amdgpu_psp.cto usesysfs_emit()instead which knows the size of the temporary buffer.Review
Quoted 8 lines
Issue found with Coccinelle.
Signed-off-by Sumera Priyadarsini <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.cdrivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static ssize_t psp_usbc_pd_fw_sysfs_read(struct
Quoted 4 lines
index
d6c38e24f130..4d1d1e1b005d100644drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -2621,7 +2621,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_read(structdevice *dev,
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static ssize_t psp_usbc_pd_fw_sysfs_read(struct device *dev, · line 2624
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-1return 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
Quoted 4 lines
thanks,
greg k-h