dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state
@ 2023-03-02  9:15 Oded Gabbay
  2023-03-02  9:15 ` [PATCH 2/2] habanalabs: use scnprintf() in print_device_in_use_info() Oded Gabbay
  2023-03-02 10:27 ` [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state Stanislaw Gruszka
  0 siblings, 2 replies; 4+ messages in thread
From: Oded Gabbay @ 2023-03-02  9:15 UTC (permalink / raw)
  To: dri-devel; +Cc: Dafna Hirschfeld

From: Dafna Hirschfeld <dhirschfeld@habana.ai>

print more informative message when failing in dirty state

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
---
 drivers/accel/habanalabs/gaudi2/gaudi2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c
index 58e3bffb8c25..99af319cd023 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c
@@ -2896,7 +2896,7 @@ static int gaudi2_early_init(struct hl_device *hdev)
 		dev_dbg(hdev->dev, "H/W state is dirty, must reset before initializing\n");
 		rc = hdev->asic_funcs->hw_fini(hdev, true, false);
 		if (rc) {
-			dev_err(hdev->dev, "failed to reset HW during early init (%d)\n", rc);
+			dev_err(hdev->dev, "failed to reset HW in dirty state (%d)\n", rc);
 			goto pci_fini;
 		}
 	}
-- 
2.39.2


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

* [PATCH 2/2] habanalabs: use scnprintf() in print_device_in_use_info()
  2023-03-02  9:15 [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state Oded Gabbay
@ 2023-03-02  9:15 ` Oded Gabbay
  2023-03-02 10:25   ` Stanislaw Gruszka
  2023-03-02 10:27 ` [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state Stanislaw Gruszka
  1 sibling, 1 reply; 4+ messages in thread
From: Oded Gabbay @ 2023-03-02  9:15 UTC (permalink / raw)
  To: dri-devel; +Cc: Stanislaw Gruszka, Tomer Tayar

From: Tomer Tayar <ttayar@habana.ai>

compose_device_in_use_info() was added to handle the snprintf() return
value in a single place.
However, the buffer size in print_device_in_use_info() is set such that
it would be enough for the max possible print, so
compose_device_in_use_info() is not really needed.
Moreover, scnprintf() can be used instead of snprintf(), to save the
check if the return value larger than the given size.

Cc: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
---
 drivers/accel/habanalabs/common/device.c | 36 +++++++-----------------
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c
index 99e793dfb126..8db00cb3b71d 100644
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -482,48 +482,32 @@ int hl_hpriv_put(struct hl_fpriv *hpriv)
 	return kref_put(&hpriv->refcount, hpriv_release);
 }
 
-static void compose_device_in_use_info(char **buf, size_t *buf_size, const char *fmt, ...)
-{
-	struct va_format vaf;
-	va_list args;
-	int size;
-
-	va_start(args, fmt);
-	vaf.fmt = fmt;
-	vaf.va = &args;
-
-	size = snprintf(*buf, *buf_size, "%pV", &vaf);
-	if (size >= *buf_size)
-		size = *buf_size;
-
-	*buf += size;
-	*buf_size -= size;
-
-	va_end(args);
-}
-
 static void print_device_in_use_info(struct hl_device *hdev, const char *message)
 {
 	u32 active_cs_num, dmabuf_export_cnt;
-	char buf[64], *buf_ptr = buf;
-	size_t buf_size = sizeof(buf);
 	bool unknown_reason = true;
+	char buf[128];
+	size_t size;
+	int offset;
+
+	size = sizeof(buf);
+	offset = 0;
 
 	active_cs_num = hl_get_active_cs_num(hdev);
 	if (active_cs_num) {
 		unknown_reason = false;
-		compose_device_in_use_info(&buf_ptr, &buf_size, " [%u active CS]", active_cs_num);
+		offset += scnprintf(buf + offset, size - offset, " [%u active CS]", active_cs_num);
 	}
 
 	dmabuf_export_cnt = atomic_read(&hdev->dmabuf_export_cnt);
 	if (dmabuf_export_cnt) {
 		unknown_reason = false;
-		compose_device_in_use_info(&buf_ptr, &buf_size, " [%u exported dma-buf]",
-						dmabuf_export_cnt);
+		offset += scnprintf(buf + offset, size - offset, " [%u exported dma-buf]",
+					dmabuf_export_cnt);
 	}
 
 	if (unknown_reason)
-		compose_device_in_use_info(&buf_ptr, &buf_size, " [unknown reason]");
+		scnprintf(buf + offset, size - offset, " [unknown reason]");
 
 	dev_notice(hdev->dev, "%s%s\n", message, buf);
 }
-- 
2.39.2


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

* Re: [PATCH 2/2] habanalabs: use scnprintf() in print_device_in_use_info()
  2023-03-02  9:15 ` [PATCH 2/2] habanalabs: use scnprintf() in print_device_in_use_info() Oded Gabbay
@ 2023-03-02 10:25   ` Stanislaw Gruszka
  0 siblings, 0 replies; 4+ messages in thread
From: Stanislaw Gruszka @ 2023-03-02 10:25 UTC (permalink / raw)
  To: Oded Gabbay; +Cc: Tomer Tayar, dri-devel

On Thu, Mar 02, 2023 at 11:15:17AM +0200, Oded Gabbay wrote:
> From: Tomer Tayar <ttayar@habana.ai>
> 
> compose_device_in_use_info() was added to handle the snprintf() return
> value in a single place.
> However, the buffer size in print_device_in_use_info() is set such that
> it would be enough for the max possible print, so
> compose_device_in_use_info() is not really needed.
> Moreover, scnprintf() can be used instead of snprintf(), to save the
> check if the return value larger than the given size.
> 
> Cc: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
> Signed-off-by: Tomer Tayar <ttayar@habana.ai>
> Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>

Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>

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

* Re: [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state
  2023-03-02  9:15 [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state Oded Gabbay
  2023-03-02  9:15 ` [PATCH 2/2] habanalabs: use scnprintf() in print_device_in_use_info() Oded Gabbay
@ 2023-03-02 10:27 ` Stanislaw Gruszka
  1 sibling, 0 replies; 4+ messages in thread
From: Stanislaw Gruszka @ 2023-03-02 10:27 UTC (permalink / raw)
  To: Oded Gabbay; +Cc: Dafna Hirschfeld, dri-devel

On Thu, Mar 02, 2023 at 11:15:16AM +0200, Oded Gabbay wrote:
> From: Dafna Hirschfeld <dhirschfeld@habana.ai>
> 
> print more informative message when failing in dirty state
> 
> Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
> Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>> ---

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

end of thread, other threads:[~2023-03-02 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-02  9:15 [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state Oded Gabbay
2023-03-02  9:15 ` [PATCH 2/2] habanalabs: use scnprintf() in print_device_in_use_info() Oded Gabbay
2023-03-02 10:25   ` Stanislaw Gruszka
2023-03-02 10:27 ` [PATCH 1/2] habanalabs: unify err log of hw-fini failure in dirty state Stanislaw Gruszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox