public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: sparclinux@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Andreas Larsson <andreas@gaisler.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] oradax: allocate ccb_buf with ctx
Date: Mon, 30 Mar 2026 14:23:39 -0700	[thread overview]
Message-ID: <20260330212339.16673-1-rosenp@gmail.com> (raw)

Use a flexible array member to allocate together and avoid freeing
separately.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/sbus/char/oradax.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/sbus/char/oradax.c b/drivers/sbus/char/oradax.c
index 45df0b274491..7313585ff3a2 100644
--- a/drivers/sbus/char/oradax.c
+++ b/drivers/sbus/char/oradax.c
@@ -189,7 +189,6 @@ struct dax_cca {
 
 /* per thread CCB context */
 struct dax_ctx {
-	struct dax_ccb		*ccb_buf;
 	u64			ccb_buf_ra;	/* cached RA of ccb_buf  */
 	struct dax_cca		*ca_buf;
 	u64			ca_buf_ra;	/* cached RA of ca_buf   */
@@ -200,6 +199,7 @@ struct dax_ctx {
 	union ccb_result	result;
 	u32			ccb_count;
 	u32			fail_count;
+	struct dax_ccb		ccb_buf[];
 };
 
 /* driver public entry points */
@@ -533,7 +533,6 @@ static int dax_close(struct inode *ino, struct file *f)
 		dax_unlock_pages(ctx, i, 1);
 	}
 
-	kfree(ctx->ccb_buf);
 	kfree(ctx->ca_buf);
 	dax_stat_dbg("CCBs: %d good, %d bad", ctx->ccb_count, ctx->fail_count);
 	kfree(ctx);
@@ -643,13 +642,9 @@ static int dax_open(struct inode *inode, struct file *f)
 	struct dax_ctx *ctx = NULL;
 	int i;
 
-	ctx = kzalloc_obj(*ctx);
+	ctx = kzalloc_flex(*ctx, ccb_buf, DAX_MAX_CCBS);
 	if (ctx == NULL)
-		goto done;
-
-	ctx->ccb_buf = kzalloc_objs(struct dax_ccb, DAX_MAX_CCBS);
-	if (ctx->ccb_buf == NULL)
-		goto done;
+		return -ENOMEM;
 
 	ctx->ccb_buf_ra = virt_to_phys(ctx->ccb_buf);
 	dax_dbg("ctx->ccb_buf=0x%p, ccb_buf_ra=0x%llx",
@@ -671,8 +666,6 @@ static int dax_open(struct inode *inode, struct file *f)
 	return 0;
 
 alloc_error:
-	kfree(ctx->ccb_buf);
-done:
 	kfree(ctx);
 	return -ENOMEM;
 }
-- 
2.53.0


                 reply	other threads:[~2026-03-30 21:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260330212339.16673-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sparclinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox