From: Tomer Tayar Date: Fri, 17 Feb 2023 10:56:48 +0000 (+0200) Subject: accel/habanalabs: use scnprintf() in print_device_in_use_info() X-Git-Tag: v6.6.7~2898^2~25^2~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28fbc058f2eec0e7e59cbeb5cce1d408d76c5965;p=platform%2Fkernel%2Flinux-starfive.git accel/habanalabs: use scnprintf() in print_device_in_use_info() 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 Signed-off-by: Tomer Tayar Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Reviewed-by: Stanislaw Gruszka --- diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index 99e793d..8db00cb 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); }