Skip to content

Commit 6105f49

Browse files
outman119alexandrebelloni
authored andcommitted
i3c: dw: Simplify xfer cleanup with __free(kfree)
Convert dw-i3c-master to use __free(kfree) guards for struct dw_i3c_xfer allocations. This frees xfer objects automatically on scope exit, and removes the now-unused dw_i3c_master_free_xfer() helper. Signed-off-by: Felix Gu <ustc.gu@gmail.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260404-dw-i3c-2-v3-2-8f7d146549c1@gmail.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 256cc1f commit 6105f49

1 file changed

Lines changed: 7 additions & 26 deletions

File tree

drivers/i3c/master/dw-i3c-master.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,6 @@ dw_i3c_master_alloc_xfer(struct dw_i3c_master *master, unsigned int ncmds)
394394
return xfer;
395395
}
396396

397-
static void dw_i3c_master_free_xfer(struct dw_i3c_xfer *xfer)
398-
{
399-
kfree(xfer);
400-
}
401-
402397
static void dw_i3c_master_start_xfer_locked(struct dw_i3c_master *master)
403398
{
404399
struct dw_i3c_xfer *xfer = master->xferqueue.cur;
@@ -716,7 +711,6 @@ static void dw_i3c_master_bus_cleanup(struct i3c_master_controller *m)
716711
static int dw_i3c_ccc_set(struct dw_i3c_master *master,
717712
struct i3c_ccc_cmd *ccc)
718713
{
719-
struct dw_i3c_xfer *xfer;
720714
struct dw_i3c_cmd *cmd;
721715
int ret, pos = 0;
722716

@@ -726,7 +720,7 @@ static int dw_i3c_ccc_set(struct dw_i3c_master *master,
726720
return pos;
727721
}
728722

729-
xfer = dw_i3c_master_alloc_xfer(master, 1);
723+
struct dw_i3c_xfer *xfer __free(kfree) = dw_i3c_master_alloc_xfer(master, 1);
730724
if (!xfer)
731725
return -ENOMEM;
732726

@@ -751,22 +745,19 @@ static int dw_i3c_ccc_set(struct dw_i3c_master *master,
751745
if (xfer->cmds[0].error == RESPONSE_ERROR_IBA_NACK)
752746
ccc->err = I3C_ERROR_M2;
753747

754-
dw_i3c_master_free_xfer(xfer);
755-
756748
return ret;
757749
}
758750

759751
static int dw_i3c_ccc_get(struct dw_i3c_master *master, struct i3c_ccc_cmd *ccc)
760752
{
761-
struct dw_i3c_xfer *xfer;
762753
struct dw_i3c_cmd *cmd;
763754
int ret, pos;
764755

765756
pos = dw_i3c_master_get_addr_pos(master, ccc->dests[0].addr);
766757
if (pos < 0)
767758
return pos;
768759

769-
xfer = dw_i3c_master_alloc_xfer(master, 1);
760+
struct dw_i3c_xfer *xfer __free(kfree) = dw_i3c_master_alloc_xfer(master, 1);
770761
if (!xfer)
771762
return -ENOMEM;
772763

@@ -791,7 +782,6 @@ static int dw_i3c_ccc_get(struct dw_i3c_master *master, struct i3c_ccc_cmd *ccc)
791782
ret = xfer->ret;
792783
if (xfer->cmds[0].error == RESPONSE_ERROR_IBA_NACK)
793784
ccc->err = I3C_ERROR_M2;
794-
dw_i3c_master_free_xfer(xfer);
795785

796786
return ret;
797787
}
@@ -838,12 +828,15 @@ static int dw_i3c_master_send_ccc_cmd(struct i3c_master_controller *m,
838828
static int dw_i3c_master_daa(struct i3c_master_controller *m)
839829
{
840830
struct dw_i3c_master *master = to_dw_i3c_master(m);
841-
struct dw_i3c_xfer *xfer;
842831
struct dw_i3c_cmd *cmd;
843832
u32 olddevs, newdevs;
844833
u8 last_addr = 0;
845834
int ret, pos;
846835

836+
struct dw_i3c_xfer *xfer __free(kfree) = dw_i3c_master_alloc_xfer(master, 1);
837+
if (!xfer)
838+
return -ENOMEM;
839+
847840
ret = pm_runtime_resume_and_get(master->dev);
848841
if (ret < 0) {
849842
dev_err(master->dev,
@@ -877,15 +870,8 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
877870
ret = 0;
878871
}
879872

880-
xfer = dw_i3c_master_alloc_xfer(master, 1);
881-
if (!xfer) {
882-
ret = -ENOMEM;
883-
goto rpm_out;
884-
}
885-
886873
pos = dw_i3c_master_get_free_pos(master);
887874
if (pos < 0) {
888-
dw_i3c_master_free_xfer(xfer);
889875
ret = pos;
890876
goto rpm_out;
891877
}
@@ -910,8 +896,6 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
910896
i3c_master_add_i3c_dev_locked(m, master->devs[pos].addr);
911897
}
912898

913-
dw_i3c_master_free_xfer(xfer);
914-
915899
rpm_out:
916900
pm_runtime_put_autosuspend(master->dev);
917901
return ret;
@@ -1083,7 +1067,6 @@ static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
10831067
struct i3c_master_controller *m = i2c_dev_get_master(dev);
10841068
struct dw_i3c_master *master = to_dw_i3c_master(m);
10851069
unsigned int nrxwords = 0, ntxwords = 0;
1086-
struct dw_i3c_xfer *xfer;
10871070
int i, ret = 0;
10881071

10891072
if (!i2c_nxfers)
@@ -1103,7 +1086,7 @@ static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
11031086
nrxwords > master->caps.datafifodepth)
11041087
return -EOPNOTSUPP;
11051088

1106-
xfer = dw_i3c_master_alloc_xfer(master, i2c_nxfers);
1089+
struct dw_i3c_xfer *xfer __free(kfree) = dw_i3c_master_alloc_xfer(master, i2c_nxfers);
11071090
if (!xfer)
11081091
return -ENOMEM;
11091092

@@ -1112,7 +1095,6 @@ static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
11121095
dev_err(master->dev,
11131096
"<%s> cannot resume i3c bus master, err: %d\n",
11141097
__func__, ret);
1115-
dw_i3c_master_free_xfer(xfer);
11161098
return ret;
11171099
}
11181100

@@ -1144,7 +1126,6 @@ static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
11441126
dw_i3c_master_dequeue_xfer(master, xfer);
11451127

11461128
ret = xfer->ret;
1147-
dw_i3c_master_free_xfer(xfer);
11481129

11491130
pm_runtime_put_autosuspend(master->dev);
11501131
return ret;

0 commit comments

Comments
 (0)