From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7BBCBFD88D3 for ; Wed, 11 Mar 2026 00:45:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E503B10E7A3; Wed, 11 Mar 2026 00:45:19 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BoruuPns"; dkim-atps=neutral Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) by gabe.freedesktop.org (Postfix) with ESMTPS id 397E610E7A3 for ; Wed, 11 Mar 2026 00:45:19 +0000 (UTC) Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-79863ab8478so127094327b3.3 for ; Tue, 10 Mar 2026 17:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773189918; x=1773794718; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/HjYa2gOXaWM1arUomc63S1ckHjrnGQ1H+F6LEklrto=; b=BoruuPnsSeHZpGXIICXLO66gLbLTjc5IwE/thgkZt1prJs19Jl0+ARFrrlMa6nv7nF oGuhBqwF7j5O2MPnJ+1o6fHHUzgzkGP3bwHqfwzy2tq8agUxbjPZ1lQKOXYoqsqmaX8w naaEjjlzxnc2C0pxGG5twrYIrif/GorR9+MhbujQ2ADtsNBjGJEU54Ghr9zC2scr9u/4 ybQ7UPHARP7uzlYNCyPpC4aUKFhrbLYBgmbzdgFulZmUR1kGdXsAaAta+T5IR1hNNkfR DH7qoLN1gMPJV00zZz5FAxtEbdkU2BGGmAaVGAWbPTlUGm2aXcKNLOyZMd3E13XT/Plq Z5XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773189918; x=1773794718; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/HjYa2gOXaWM1arUomc63S1ckHjrnGQ1H+F6LEklrto=; b=ottacFP/aziqcHx0Sus6Tx/Ax2LlG74w3U7iQpPy6slG9GLHIjfeOmslRN9/JMVFiG 6jHz9cJrPISrcF0/KxodqldGuNAHoVcKuvjvCnKU/U8pTvO1D46U0Y7JqhOCw86WODDm MGpoHG5NKKiW9TlSFz1Up6z0pgL6puTstodIUAGcEo3H7J779QSeRx/bgrjEAQnceiqb 4oHfRSQXQ38HqIYyFcqSlt6xeeutCOBlv3IadV86tI/zELQEICaynR9t5HIg6a+CVp74 2wQh0jbqeS3OCrdJO+SvttdqDosxYcZ41Oy/uOFX8G+EIL1q6a5Jvco36rDTi58OzZJ7 CBUA== X-Forwarded-Encrypted: i=1; AJvYcCXVtQm5ijSxhswQ1dFQeAbph+2f+29cANv1fkudUD20rxEEVWZsPv3q/aNbxNnI7zW8bmjUjNdFwfg=@lists.freedesktop.org X-Gm-Message-State: AOJu0Yzkj6LjI2/1Yy3Q18AAzFI6rVs9WQFtk1bniuzvvlJUH9mVfXBF TZrn8uoUn6PEU4VtlEMq464CkdX0fPSu9IXQUluHYtpUjWaA/N8SoNWv X-Gm-Gg: ATEYQzyVsRQByKNVCfwUoO20qFd2QE6f3ETk2FzAUN9f2KBTAdfOHvelYUxxRA5WL0N Sofyc2KUVO5LHsIMACdtrU58foNjetS4vWTylDuQklv096aO6VvdjiwzxHohhYhvmbZSIFyTvd8 NX1ZwWHkSY8xMprIdAVH60LAKFHkAs9HcHHHbXhA4WHMHqKN7dno5M3nqTs9ms+elL0avRAXUZv gJA8TK9DtR5FUhFwZlOj+XdOjZJb8f758I6LHHFq0m76iYJRmPEuNRijKcJm68LNuAHgGImCHmG jIp7GFuAuXaGSIPwAdbrhID8xa9q13NwZThpy8D776yEgP/BQSkK6AZg7W6/yoq0m2G0rRMf/GK xQzG1ZsrSKLLua5MlFPFD0+WvrDMsE84oyxFKevckNzTWCZMnd8uVZQIDGf+Y5SQOEHpCS8FtWt Bwz5/3wLvdniSKNtSBgqBHI8TTPoQ5EwbsVgSTDuF7zwbK3cCV1rJ/1Q== X-Received: by 2002:a05:690c:22c5:b0:798:798d:9a1b with SMTP id 00721157ae682-79917ff2032mr6016447b3.63.1773189917927; Tue, 10 Mar 2026 17:45:17 -0700 (PDT) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79917ee4fc6sm3610357b3.29.2026.03.10.17.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2026 17:45:17 -0700 (PDT) From: Rosen Penev To: "dri-devel@linux-kernel"@vger.kernel.org Cc: Koby Elbaz , Konstantin Sinyuk , Oded Gabbay , dri-devel@lists.freedesktop.org (open list:HABANALABS PCI DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] accel/habanalabs: kzalloc + kcalloc to kzalloc_flex Date: Tue, 10 Mar 2026 17:44:59 -0700 Message-ID: <20260311004459.32567-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Simplifies allocation by using a flexible array member. No need to free separately. Signed-off-by: Rosen Penev --- .../habanalabs/common/command_submission.c | 20 ++----------------- drivers/accel/habanalabs/common/habanalabs.h | 2 +- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c index ba4257bda77b..ba99329eacbd 100644 --- a/drivers/accel/habanalabs/common/command_submission.c +++ b/drivers/accel/habanalabs/common/command_submission.c @@ -809,7 +809,6 @@ static void cs_do_release(struct kref *ref) hl_fence_put(cs->fence); - kfree(cs->jobs_in_queue_cnt); kfree(cs); } @@ -907,9 +906,9 @@ static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx, cntr = &hdev->aggregated_cs_counters; - cs = kzalloc_obj(*cs, GFP_ATOMIC); + cs = kzalloc_flex(*cs, jobs_in_queue_cnt, hdev->asic_prop.max_queues, GFP_ATOMIC); if (!cs) - cs = kzalloc_obj(*cs); + cs = kzalloc_flex(*cs, jobs_in_queue_cnt, hdev->asic_prop.max_queues); if (!cs) { atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt); @@ -947,19 +946,6 @@ static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx, goto free_cs; } - cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, - sizeof(*cs->jobs_in_queue_cnt), GFP_ATOMIC); - if (!cs->jobs_in_queue_cnt) - cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, - sizeof(*cs->jobs_in_queue_cnt), GFP_KERNEL); - - if (!cs->jobs_in_queue_cnt) { - atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt); - atomic64_inc(&cntr->out_of_mem_drop_cnt); - rc = -ENOMEM; - goto free_cs_cmpl; - } - cs_cmpl->hdev = hdev; cs_cmpl->type = cs->type; spin_lock_init(&cs_cmpl->lock); @@ -1014,8 +1000,6 @@ static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx, free_fence: spin_unlock(&ctx->cs_lock); - kfree(cs->jobs_in_queue_cnt); -free_cs_cmpl: kfree(cs_cmpl); free_cs: kfree(cs); diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index d94c2ba22a6a..dc13c8a6f242 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -2046,7 +2046,6 @@ struct hl_userptr { * @encaps_signals: true if this CS has encaps reserved signals. */ struct hl_cs { - u16 *jobs_in_queue_cnt; struct hl_ctx *ctx; struct list_head job_list; spinlock_t job_lock; @@ -2080,6 +2079,7 @@ struct hl_cs { u8 staged_cs; u8 skip_reset_on_timeout; u8 encaps_signals; + u16 jobs_in_queue_cnt[]; }; /** -- 2.53.0