From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
To: jic23@kernel.org, m.tretter@pengutronix.de, mchehab@kernel.org,
p.zabel@pengutronix.de, tiffany.lin@mediatek.com,
andrew-ct.chen@mediatek.com, yunfei.dong@mediatek.com,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org,
pure.logic@nexus-software.ie
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
kernel@pengutronix.de, kees@kernel.org,
nabijaczleweli@nabijaczleweli.xyz, marcelo.schmitt1@gmail.com,
maudspierings@gocontroll.com, hverkuil+cisco@kernel.org,
ribalda@chromium.org, straube.linux@gmail.com,
dan.carpenter@linaro.org, lukagejak5@gmail.com,
ethantidmore06@gmail.com, samasth.norway.ananda@oracle.com,
karanja99erick@gmail.com, s9430939@naver.com, tglx@kernel.org,
mingo@kernel.org, sun.jian.kdev@gmail.com, weibu@redadmin.org,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, greybus-dev@lists.linaro.org,
linux-staging@lists.linux.dev, sanjayembeddedse@gmail.com,
skhan@linuxfoundation.org
Subject: [PATCH 5/7] media: chips-media: coda: simplify cleanup using __free
Date: Wed, 11 Mar 2026 01:35:11 +0530 [thread overview]
Message-ID: <20260310200513.2162018-6-sanjayembedded@gmail.com> (raw)
In-Reply-To: <20260310200513.2162018-1-sanjayembedded@gmail.com>
From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
Replace manual cleanup logic with __free attribute from cleanup.h. This
removes explicit kfree() calls and simplifies the error handling paths.
No functional change intended for kmalloc()/kzalloc_obj().
Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
.../platform/chips-media/coda/coda-bit.c | 4 +-
.../platform/chips-media/coda/coda-jpeg.c | 39 +++++++------------
2 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/drivers/media/platform/chips-media/coda/coda-bit.c b/drivers/media/platform/chips-media/coda/coda-bit.c
index b0559303c40f..958e245d0698 100644
--- a/drivers/media/platform/chips-media/coda/coda-bit.c
+++ b/drivers/media/platform/chips-media/coda/coda-bit.c
@@ -183,19 +183,17 @@ static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx)
static int coda_h264_bitstream_pad(struct coda_ctx *ctx, u32 size)
{
- unsigned char *buf;
u32 n;
if (size < 6)
size = 6;
- buf = kmalloc(size, GFP_KERNEL);
+ unsigned char *buf __free(kfree) = kmalloc(size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
coda_h264_filler_nal(size, buf);
n = kfifo_in(&ctx->bitstream_fifo, buf, size);
- kfree(buf);
return (n < size) ? -ENOSPC : 0;
}
diff --git a/drivers/media/platform/chips-media/coda/coda-jpeg.c b/drivers/media/platform/chips-media/coda/coda-jpeg.c
index 835225383aa1..11f2800014e5 100644
--- a/drivers/media/platform/chips-media/coda/coda-jpeg.c
+++ b/drivers/media/platform/chips-media/coda/coda-jpeg.c
@@ -584,16 +584,15 @@ static int coda9_jpeg_gen_enc_huff_tab(struct coda_ctx *ctx, int tab_num,
{
int i, j, k, lastk, si, code, maxsymbol;
const u8 *bits, *huffval;
- struct {
- int size[256];
- int code[256];
- } *huff;
static const unsigned char *huff_tabs[4] = {
luma_dc, luma_ac, chroma_dc, chroma_ac,
};
int ret = -EINVAL;
- huff = kzalloc_obj(*huff);
+ struct {
+ int size[256];
+ int code[256];
+ } *huff __free(kfree) = kzalloc_obj(*huff);
if (!huff)
return -ENOMEM;
@@ -607,7 +606,7 @@ static int coda9_jpeg_gen_enc_huff_tab(struct coda_ctx *ctx, int tab_num,
for (i = 1; i <= 16; i++) {
j = bits[i - 1];
if (k + j > maxsymbol)
- goto out;
+ return ret;
while (j--)
huff->size[k++] = i;
}
@@ -623,7 +622,7 @@ static int coda9_jpeg_gen_enc_huff_tab(struct coda_ctx *ctx, int tab_num,
code++;
}
if (code >= (1 << si))
- goto out;
+ return ret;
code <<= 1;
si++;
}
@@ -632,15 +631,12 @@ static int coda9_jpeg_gen_enc_huff_tab(struct coda_ctx *ctx, int tab_num,
for (k = 0; k < lastk; k++) {
i = huffval[k];
if (i >= maxsymbol || ehufsi[i])
- goto out;
+ return ret;
ehufco[i] = huff->code[k];
ehufsi[i] = huff->size[k];
}
- ret = 0;
-out:
- kfree(huff);
- return ret;
+ return 0;
}
#define DC_TABLE_INDEX0 0
@@ -715,15 +711,14 @@ static int coda9_jpeg_gen_dec_huff_tab(struct coda_ctx *ctx, int tab_num)
static int coda9_jpeg_load_huff_tab(struct coda_ctx *ctx)
{
- struct {
- int size[4][256];
- int code[4][256];
- } *huff;
u32 *huff_data;
int i, j;
int ret;
- huff = kzalloc_obj(*huff);
+ struct {
+ int size[4][256];
+ int code[4][256];
+ } *huff __free(kfree) = kzalloc_obj(*huff);
if (!huff)
return -ENOMEM;
@@ -732,7 +727,7 @@ static int coda9_jpeg_load_huff_tab(struct coda_ctx *ctx)
ret = coda9_jpeg_gen_enc_huff_tab(ctx, i, huff->size[i],
huff->code[i]);
if (ret)
- goto out;
+ return ret;
}
if (!ctx->params.jpeg_huff_data) {
@@ -740,8 +735,7 @@ static int coda9_jpeg_load_huff_tab(struct coda_ctx *ctx)
kzalloc(sizeof(u32) * CODA9_JPEG_ENC_HUFF_DATA_SIZE,
GFP_KERNEL);
if (!ctx->params.jpeg_huff_data) {
- ret = -ENOMEM;
- goto out;
+ return -ENOMEM;
}
}
huff_data = ctx->params.jpeg_huff_data;
@@ -765,10 +759,7 @@ static int coda9_jpeg_load_huff_tab(struct coda_ctx *ctx)
}
}
- ret = 0;
-out:
- kfree(huff);
- return ret;
+ return 0;
}
static void coda9_jpeg_write_huff_tab(struct coda_ctx *ctx)
--
2.34.1
next prev parent reply other threads:[~2026-03-10 20:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 20:05 [PATCH 0/7] drivers: Simplify cleanup paths using __free Sanjay Chitroda
2026-03-10 20:05 ` [PATCH 1/7] staging: greybus: simplify cleanup " Sanjay Chitroda
2026-03-10 21:07 ` Andy Shevchenko
2026-03-11 6:51 ` Dan Carpenter
2026-03-11 7:06 ` Greg KH
2026-03-10 20:05 ` [PATCH 2/7] iio: ssp_sensors: " Sanjay Chitroda
2026-03-10 21:11 ` Andy Shevchenko
2026-03-10 20:05 ` [PATCH 3/7] iio: st_sensors: " Sanjay Chitroda
2026-03-11 0:04 ` David Lechner
2026-03-10 20:05 ` [PATCH 4/7] media: mediatek: vcodec: " Sanjay Chitroda
2026-03-19 21:08 ` Nicolas Dufresne
2026-03-10 20:05 ` Sanjay Chitroda [this message]
2026-03-10 20:05 ` [PATCH 6/7] media: allegro: " Sanjay Chitroda
2026-03-10 20:05 ` [PATCH 7/7] staging: rtl8723bs: " Sanjay Chitroda
2026-03-10 21:42 ` Andrew Lunn
2026-03-11 6:45 ` Greg KH
2026-03-10 21:04 ` [PATCH 0/7] drivers: Simplify cleanup paths " Andy Shevchenko
2026-03-10 21:52 ` David Lechner
2026-03-11 1:57 ` Sanjay Chitroda
2026-03-11 5:42 ` Luka Gejak
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=20260310200513.2162018-6-sanjayembedded@gmail.com \
--to=sanjayembeddedse@gmail.com \
--cc=andrew-ct.chen@mediatek.com \
--cc=andy@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=dan.carpenter@linaro.org \
--cc=dlechner@baylibre.com \
--cc=elder@kernel.org \
--cc=ethantidmore06@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=hverkuil+cisco@kernel.org \
--cc=jic23@kernel.org \
--cc=johan@kernel.org \
--cc=karanja99erick@gmail.com \
--cc=kees@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-staging@lists.linux.dev \
--cc=lukagejak5@gmail.com \
--cc=m.tretter@pengutronix.de \
--cc=marcelo.schmitt1@gmail.com \
--cc=matthias.bgg@gmail.com \
--cc=maudspierings@gocontroll.com \
--cc=mchehab@kernel.org \
--cc=mingo@kernel.org \
--cc=nabijaczleweli@nabijaczleweli.xyz \
--cc=nuno.sa@analog.com \
--cc=p.zabel@pengutronix.de \
--cc=pure.logic@nexus-software.ie \
--cc=ribalda@chromium.org \
--cc=s9430939@naver.com \
--cc=samasth.norway.ananda@oracle.com \
--cc=skhan@linuxfoundation.org \
--cc=straube.linux@gmail.com \
--cc=sun.jian.kdev@gmail.com \
--cc=tglx@kernel.org \
--cc=tiffany.lin@mediatek.com \
--cc=weibu@redadmin.org \
--cc=yunfei.dong@mediatek.com \
/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