Skip to contentSkip to conversation

drm/amdgpu: Replace snprintf() with sysfs_emit

PATCH In review Sumera Priyadarsini 4 participants 13 messages Oct 22, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw
Quoted 14 lines · Sumera Priyadarsini

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()

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

#5 lore raw

PATCH 1/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

In reply to Sumera Priyadarsini

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.

---
 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
index 469352e2d6ec..3c19862c94c7 100644
@@ -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
#6 lore raw

PATCH 2/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

In reply to Sumera Priyadarsini

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.

---
 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
index f7307af76452..7eef6b20578f 100644
@@ -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
#7 lore raw

PATCH 3/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

In reply to Sumera Priyadarsini

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.

---
 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
index 1721739def84..441e07ee1967 100644
@@ -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
#8 lore raw

PATCH 4/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

In reply to Sumera Priyadarsini

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.

---
 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
index d6c38e24f130..4d1d1e1b005d 100644
@@ -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
#2 lore raw
In reply to Greg KH
Quoted 16 lines · Greg KH
Quoted 14 lines · Sumera Priyadarsini

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()

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
#11 lore raw

PATCH 5/5 gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

In reply to Sumera Priyadarsini

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.

---
 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
index e5ea14774c0c..6d9901e1b4b0 100644
@@ -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
#9 lore raw

Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

In reply to Sumera Priyadarsini
Quoted 19 lines · Sumera Priyadarsini

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.

---
 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
index d6c38e24f130..4d1d1e1b005d 100644

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

#3 lore raw
In reply to Vaishali Thakkar
Quoted 24 lines · Vaishali Thakkar,
Quoted 22 lines · Greg KH
Quoted 19 lines · Sumera Priyadarsini

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 ++--
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 Google

Groups "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

#12 lore raw
In reply to Sumera Priyadarsini
Quoted 6 lines · Sumera Priyadarsini

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

Quoted 18 lines

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
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw
In reply to Sumera Priyadarsini
Quoted 28 lines · Sumera Priyadarsini
Quoted 24 lines · Vaishali Thakkar,
Quoted 22 lines · Greg KH
Quoted 19 lines · Sumera Priyadarsini

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 ++--
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,
Sumera

Quoted 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
#10 lore raw

Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()

In reply to Greg KH
Quoted 22 lines · Greg KH
Quoted 7 lines · Sumera Priyadarsini

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.

Review

Quoted 8 lines

Issue found with Coccinelle.

---
 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.c

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static ssize_t psp_usbc_pd_fw_sysfs_read(struct

Quoted 4 lines

index d6c38e24f130..4d1d1e1b005d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0 -0
@@ -2621,7 +2621,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_read(struct

device *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 -1
              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

Quoted 4 lines

thanks,

greg k-h