All of lore.kernel.org
 help / color / mirror / Atom feed
* [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
@ 2020-10-22 13:37 ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:31 UTC (permalink / raw)
  To: sylphrenadin; +Cc: outreachy-kernel

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



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
  2020-10-22 13:37 ` Sumera Priyadarsini
                   ` (2 preceding siblings ...)
  (?)
@ 2020-10-22 13:37 ` Greg KH
  2020-10-22 13:49   ` Vaishali Thakkar
  -1 siblings, 1 reply; 32+ messages in thread
From: Greg KH @ 2020-10-22 13:37 UTC (permalink / raw)
  To: Sumera Priyadarsini; +Cc: outreachy-kernel

On Thu, Oct 22, 2020 at 07:01:44PM +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.
> 
> 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 ++--

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


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
@ 2020-10-22 13:37 ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:37 UTC (permalink / raw)
  To: dri-devel
  Cc: outreachy-kernel, alexander.deucher, christian.koenig, airlied,
	daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
@ 2020-10-22 13:37 ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:37 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	alexander.deucher, christian.koenig, linux-media

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
@ 2020-10-22 13:37 ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:37 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	daniel, alexander.deucher, christian.koenig, linux-media

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

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 1/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  2020-10-22 13:37 ` Sumera Priyadarsini
  (?)
@ 2020-10-22 13:40   ` Sumera Priyadarsini
  -1 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:40 UTC (permalink / raw)
  To: dri-devel
  Cc: outreachy-kernel, alexander.deucher, christian.koenig, airlied,
	daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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



^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 1/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:40   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:40 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	alexander.deucher, christian.koenig, linux-media

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 1/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:40   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:40 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	daniel, alexander.deucher, christian.koenig, linux-media

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

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 2/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  2020-10-22 13:37 ` Sumera Priyadarsini
  (?)
@ 2020-10-22 13:43   ` Sumera Priyadarsini
  -1 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:43 UTC (permalink / raw)
  To: dri-devel
  Cc: outreachy-kernel, alexander.deucher, christian.koenig, airlied,
	daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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



^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 2/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:43   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:43 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	alexander.deucher, christian.koenig, linux-media

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 2/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:43   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:43 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	daniel, alexander.deucher, christian.koenig, linux-media

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

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 3/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  2020-10-22 13:37 ` Sumera Priyadarsini
  (?)
@ 2020-10-22 13:47   ` Sumera Priyadarsini
  -1 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:47 UTC (permalink / raw)
  To: dri-devel
  Cc: outreachy-kernel, alexander.deucher, christian.koenig, airlied,
	daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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



^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 3/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:47   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:47 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	alexander.deucher, christian.koenig, linux-media

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 3/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:47   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:47 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	daniel, alexander.deucher, christian.koenig, linux-media

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

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  2020-10-22 13:37 ` Sumera Priyadarsini
  (?)
@ 2020-10-22 13:47   ` Sumera Priyadarsini
  -1 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:47 UTC (permalink / raw)
  To: dri-devel
  Cc: outreachy-kernel, alexander.deucher, christian.koenig, airlied,
	daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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



^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:47   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:47 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	alexander.deucher, christian.koenig, linux-media

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:47   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:47 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	daniel, alexander.deucher, christian.koenig, linux-media

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

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
  2020-10-22 13:37 ` Greg KH
@ 2020-10-22 13:49   ` Vaishali Thakkar
  2020-10-22 14:12     ` Sumera Priyadarsini
  0 siblings, 1 reply; 32+ messages in thread
From: Vaishali Thakkar @ 2020-10-22 13:49 UTC (permalink / raw)
  To: Greg KH; +Cc: Sumera Priyadarsini, Outreachy

On Thu, Oct 22, 2020 at 7:06 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Oct 22, 2020 at 07:01:44PM +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.
> >
> > 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 ++--
>
> 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.

> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20201022133722.GA1784385%40kroah.com.



-- 
Vaishali


-- 
Vaishali


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 5/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  2020-10-22 13:37 ` Sumera Priyadarsini
  (?)
@ 2020-10-22 13:49   ` Sumera Priyadarsini
  -1 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:49 UTC (permalink / raw)
  To: dri-devel
  Cc: outreachy-kernel, alexander.deucher, christian.koenig, airlied,
	daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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



^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 5/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:49   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:49 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	alexander.deucher, christian.koenig, linux-media

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 5/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:49   ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 13:49 UTC (permalink / raw)
  To: dri-devel
  Cc: airlied, linux-kernel, amd-gfx, melissa.srw, outreachy-kernel,
	daniel, alexander.deucher, christian.koenig, linux-media

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

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  2020-10-22 13:47   ` Sumera Priyadarsini
  (?)
@ 2020-10-22 13:54     ` Greg KH
  -1 siblings, 0 replies; 32+ messages in thread
From: Greg KH @ 2020-10-22 13:54 UTC (permalink / raw)
  To: Sumera Priyadarsini
  Cc: dri-devel, outreachy-kernel, alexander.deucher, christian.koenig,
	airlied, daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:54     ` Greg KH
  0 siblings, 0 replies; 32+ messages in thread
From: Greg KH @ 2020-10-22 13:54 UTC (permalink / raw)
  To: Sumera Priyadarsini
  Cc: airlied, linux-kernel, dri-devel, melissa.srw, outreachy-kernel,
	amd-gfx, alexander.deucher, christian.koenig, linux-media

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
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 13:54     ` Greg KH
  0 siblings, 0 replies; 32+ messages in thread
From: Greg KH @ 2020-10-22 13:54 UTC (permalink / raw)
  To: Sumera Priyadarsini
  Cc: airlied, linux-kernel, dri-devel, melissa.srw, outreachy-kernel,
	amd-gfx, daniel, alexander.deucher, christian.koenig,
	linux-media

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

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
  2020-10-22 13:49   ` Vaishali Thakkar
@ 2020-10-22 14:12     ` Sumera Priyadarsini
  2020-10-22 14:17       ` Vaishali Thakkar
  0 siblings, 1 reply; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 14:12 UTC (permalink / raw)
  To: Vaishali Thakkar; +Cc: Greg KH, Outreachy

[-- Attachment #1: Type: text/plain, Size: 2408 bytes --]

On Thu, 22 Oct, 2020, 7:19 PM Vaishali Thakkar, <vthakkar@vaishalithakkar.in>
wrote:

> On Thu, Oct 22, 2020 at 7:06 PM Greg KH <gregkh@linuxfoundation.org>
> wrote:
> >
> > On Thu, Oct 22, 2020 at 07:01:44PM +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.
> > >
> > > 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 ++--
> >
> > 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
> 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

> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/outreachy-kernel/20201022133722.GA1784385%40kroah.com
> .
>
>
>
> --
> Vaishali
>
>
> --
> Vaishali
>

[-- Attachment #2: Type: text/html, Size: 3944 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
  2020-10-22 13:37 ` Sumera Priyadarsini
  (?)
@ 2020-10-22 14:13   ` Daniel Vetter
  -1 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2020-10-22 14:13 UTC (permalink / raw)
  To: Sumera Priyadarsini
  Cc: dri-devel, outreachy-kernel, alexander.deucher, christian.koenig,
	airlied, daniel, melissa.srw, linux-media, amd-gfx, linux-kernel

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


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
@ 2020-10-22 14:13   ` Daniel Vetter
  0 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2020-10-22 14:13 UTC (permalink / raw)
  To: Sumera Priyadarsini
  Cc: airlied, linux-kernel, dri-devel, melissa.srw, outreachy-kernel,
	amd-gfx, alexander.deucher, christian.koenig, linux-media

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
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
@ 2020-10-22 14:13   ` Daniel Vetter
  0 siblings, 0 replies; 32+ messages in thread
From: Daniel Vetter @ 2020-10-22 14:13 UTC (permalink / raw)
  To: Sumera Priyadarsini
  Cc: airlied, linux-kernel, dri-devel, melissa.srw, outreachy-kernel,
	amd-gfx, daniel, alexander.deucher, christian.koenig,
	linux-media

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

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit
  2020-10-22 14:12     ` Sumera Priyadarsini
@ 2020-10-22 14:17       ` Vaishali Thakkar
  0 siblings, 0 replies; 32+ messages in thread
From: Vaishali Thakkar @ 2020-10-22 14:17 UTC (permalink / raw)
  To: Sumera Priyadarsini; +Cc: Greg KH, Outreachy

On Thu, Oct 22, 2020 at 7:43 PM Sumera Priyadarsini
<sylphrenadin@gmail.com> wrote:
>
>
>
> On Thu, 22 Oct, 2020, 7:19 PM Vaishali Thakkar, <vthakkar@vaishalithakkar.in> wrote:
>>
>> On Thu, Oct 22, 2020 at 7:06 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>> >
>> > On Thu, Oct 22, 2020 at 07:01:44PM +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.
>> > >
>> > > 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 ++--
>> >
>> > 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. :(

>> 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
>
>> > 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 outreachy-kernel+unsubscribe@googlegroups.com.
>> > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20201022133722.GA1784385%40kroah.com.
>>
>>
>>
>> --
>> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CACAkLuoubwnXBEHGry9kLy_YStwXu9bR%3DdGndt0Dx6JdJM%2B8LQ%40mail.gmail.com.



-- 
Vaishali


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
  2020-10-22 13:54     ` Greg KH
  (?)
@ 2020-10-22 21:40       ` Sumera Priyadarsini
  -1 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 21:40 UTC (permalink / raw)
  To: Greg KH
  Cc: airlied, linux-kernel, dri-devel, Melissa Wen, Outreachy,
	amd-gfx, alexander.deucher, christian.koenig, linux-media


[-- 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: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 21:40       ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 21:40 UTC (permalink / raw)
  To: Greg KH
  Cc: airlied, linux-kernel, dri-devel, Melissa Wen, Outreachy,
	amd-gfx, Daniel Vetter, alexander.deucher, christian.koenig,
	linux-media


[-- 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

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [Outreachy kernel] [PATCH 4/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
@ 2020-10-22 21:40       ` Sumera Priyadarsini
  0 siblings, 0 replies; 32+ messages in thread
From: Sumera Priyadarsini @ 2020-10-22 21:40 UTC (permalink / raw)
  To: Greg KH
  Cc: dri-devel, Outreachy, alexander.deucher, christian.koenig,
	airlied, Daniel Vetter, Melissa Wen, linux-media, amd-gfx,
	linux-kernel

[-- Attachment #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 #2: Type: text/html, Size: 2303 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2020-10-23  7:23 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 13:31 [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit Sumera Priyadarsini
2020-10-22 13:37 ` Sumera Priyadarsini
2020-10-22 13:37 ` Sumera Priyadarsini
2020-10-22 13:37 ` Sumera Priyadarsini
2020-10-22 13:37 ` Greg KH
2020-10-22 13:49   ` Vaishali Thakkar
2020-10-22 14:12     ` Sumera Priyadarsini
2020-10-22 14:17       ` Vaishali Thakkar
2020-10-22 13:40 ` [PATCH 1/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() Sumera Priyadarsini
2020-10-22 13:40   ` Sumera Priyadarsini
2020-10-22 13:40   ` Sumera Priyadarsini
2020-10-22 13:43 ` [PATCH 2/5] " Sumera Priyadarsini
2020-10-22 13:43   ` Sumera Priyadarsini
2020-10-22 13:43   ` Sumera Priyadarsini
2020-10-22 13:47 ` [PATCH 3/5] " Sumera Priyadarsini
2020-10-22 13:47   ` Sumera Priyadarsini
2020-10-22 13:47   ` Sumera Priyadarsini
2020-10-22 13:47 ` [PATCH 4/5] " Sumera Priyadarsini
2020-10-22 13:47   ` Sumera Priyadarsini
2020-10-22 13:47   ` Sumera Priyadarsini
2020-10-22 13:54   ` [Outreachy kernel] " Greg KH
2020-10-22 13:54     ` Greg KH
2020-10-22 13:54     ` Greg KH
2020-10-22 21:40     ` Sumera Priyadarsini
2020-10-22 21:40       ` Sumera Priyadarsini
2020-10-22 21:40       ` Sumera Priyadarsini
2020-10-22 13:49 ` [PATCH 5/5] " Sumera Priyadarsini
2020-10-22 13:49   ` Sumera Priyadarsini
2020-10-22 13:49   ` Sumera Priyadarsini
2020-10-22 14:13 ` [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit Daniel Vetter
2020-10-22 14:13   ` Daniel Vetter
2020-10-22 14:13   ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.