drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 -- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 13 ++----------- drivers/infiniband/ulp/rtrs/rtrs-clt.h | 2 +- 3 files changed, 3 insertions(+), 14 deletions(-)
Store the client path statistics in the RTRS client path allocation
instead of allocating them separately.
This ties the stats lifetime directly to the path and removes a separate
allocation failure path. Keep freeing the per-CPU stats data separately,
but do not free the embedded stats object from error paths or the stats
kobject release handler.
Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 --
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 13 ++-----------
drivers/infiniband/ulp/rtrs/rtrs-clt.h | 2 +-
3 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c
index 287e0ea43287..f8b833bd81ad 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c
@@ -37,8 +37,6 @@ static void rtrs_clt_path_stats_release(struct kobject *kobj)
stats = container_of(kobj, struct rtrs_clt_stats, kobj_stats);
free_percpu(stats->pcpu_stats);
-
- kfree(stats);
}
static struct kobj_type ktype_stats = {
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index e351552733df..d34d7e5f34d6 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1536,7 +1536,7 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
int cpu;
size_t total_con;
- clt_path = kzalloc_obj(*clt_path);
+ clt_path = kzalloc_flex(*clt_path, stats, 1);
if (!clt_path)
goto err;
@@ -1552,10 +1552,6 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
clt_path->s.con_num = total_con;
clt_path->s.irq_con_num = con_num + 1;
- clt_path->stats = kzalloc_obj(*clt_path->stats);
- if (!clt_path->stats)
- goto err_free_con;
-
mutex_init(&clt_path->init_mutex);
uuid_gen(&clt_path->s.uuid);
memcpy(&clt_path->s.dst_addr, path->dst,
@@ -1583,7 +1579,7 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
clt_path->mp_skip_entry = alloc_percpu(typeof(*clt_path->mp_skip_entry));
if (!clt_path->mp_skip_entry)
- goto err_free_stats;
+ goto err_free_con;
for_each_possible_cpu(cpu)
INIT_LIST_HEAD(per_cpu_ptr(clt_path->mp_skip_entry, cpu));
@@ -1596,8 +1592,6 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
err_free_percpu:
free_percpu(clt_path->mp_skip_entry);
-err_free_stats:
- kfree(clt_path->stats);
err_free_con:
kfree(clt_path->s.con);
err_free_path:
@@ -2863,7 +2857,6 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,
list_del_rcu(&clt_path->s.entry);
rtrs_clt_close_conns(clt_path, true);
free_percpu(clt_path->stats->pcpu_stats);
- kfree(clt_path->stats);
free_path(clt_path);
goto close_all_path;
}
@@ -2873,7 +2866,6 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,
list_del_rcu(&clt_path->s.entry);
rtrs_clt_close_conns(clt_path, true);
free_percpu(clt_path->stats->pcpu_stats);
- kfree(clt_path->stats);
free_path(clt_path);
goto close_all_path;
}
@@ -3166,7 +3158,6 @@ int rtrs_clt_create_path_from_sysfs(struct rtrs_clt_sess *clt,
rtrs_clt_remove_path_from_arr(clt_path);
rtrs_clt_close_conns(clt_path, true);
free_percpu(clt_path->stats->pcpu_stats);
- kfree(clt_path->stats);
free_path(clt_path);
return err;
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.h b/drivers/infiniband/ulp/rtrs/rtrs-clt.h
index 986239ed2d3b..1305601a6251 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.h
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.h
@@ -142,12 +142,12 @@ struct rtrs_clt_path {
u32 flags;
struct kobject kobj;
u8 for_new_clt;
- struct rtrs_clt_stats *stats;
/* cache hca_port and hca_name to display in sysfs */
u8 hca_port;
char hca_name[IB_DEVICE_NAME_MAX];
struct list_head __percpu
*mp_skip_entry;
+ struct rtrs_clt_stats stats[];
};
struct rtrs_clt_sess {
--
2.54.0
On Sun, May 10, 2026 at 09:18:12PM -0700, Rosen Penev wrote: > Store the client path statistics in the RTRS client path allocation > instead of allocating them separately. > > This ties the stats lifetime directly to the path and removes a separate > allocation failure path. Keep freeing the per-CPU stats data separately, > but do not free the embedded stats object from error paths or the stats > kobject release handler. > > Assisted-by: Codex:GPT-5.5 > Signed-off-by: Rosen Penev <rosenp@gmail.com> > Acked-by: Jack Wang <jinpu.wang@ionos.com> > --- > drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 -- > drivers/infiniband/ulp/rtrs/rtrs-clt.c | 13 ++----------- > drivers/infiniband/ulp/rtrs/rtrs-clt.h | 2 +- > 3 files changed, 3 insertions(+), 14 deletions(-) Applied to for-next Thanks, Jason
On Mon, May 11, 2026 at 6:18 AM Rosen Penev <rosenp@gmail.com> wrote:
>
> Store the client path statistics in the RTRS client path allocation
> instead of allocating them separately.
>
> This ties the stats lifetime directly to the path and removes a separate
> allocation failure path. Keep freeing the per-CPU stats data separately,
> but do not free the embedded stats object from error paths or the stats
> kobject release handler.
>
> Assisted-by: Codex:GPT-5.5
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Thx!
Acked-by: Jack Wang <jinpu.wang@ionos.com>
> ---
> drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 --
> drivers/infiniband/ulp/rtrs/rtrs-clt.c | 13 ++-----------
> drivers/infiniband/ulp/rtrs/rtrs-clt.h | 2 +-
> 3 files changed, 3 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c
> index 287e0ea43287..f8b833bd81ad 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c
> @@ -37,8 +37,6 @@ static void rtrs_clt_path_stats_release(struct kobject *kobj)
> stats = container_of(kobj, struct rtrs_clt_stats, kobj_stats);
>
> free_percpu(stats->pcpu_stats);
> -
> - kfree(stats);
> }
>
> static struct kobj_type ktype_stats = {
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index e351552733df..d34d7e5f34d6 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -1536,7 +1536,7 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
> int cpu;
> size_t total_con;
>
> - clt_path = kzalloc_obj(*clt_path);
> + clt_path = kzalloc_flex(*clt_path, stats, 1);
> if (!clt_path)
> goto err;
>
> @@ -1552,10 +1552,6 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
> clt_path->s.con_num = total_con;
> clt_path->s.irq_con_num = con_num + 1;
>
> - clt_path->stats = kzalloc_obj(*clt_path->stats);
> - if (!clt_path->stats)
> - goto err_free_con;
> -
> mutex_init(&clt_path->init_mutex);
> uuid_gen(&clt_path->s.uuid);
> memcpy(&clt_path->s.dst_addr, path->dst,
> @@ -1583,7 +1579,7 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
>
> clt_path->mp_skip_entry = alloc_percpu(typeof(*clt_path->mp_skip_entry));
> if (!clt_path->mp_skip_entry)
> - goto err_free_stats;
> + goto err_free_con;
>
> for_each_possible_cpu(cpu)
> INIT_LIST_HEAD(per_cpu_ptr(clt_path->mp_skip_entry, cpu));
> @@ -1596,8 +1592,6 @@ static struct rtrs_clt_path *alloc_path(struct rtrs_clt_sess *clt,
>
> err_free_percpu:
> free_percpu(clt_path->mp_skip_entry);
> -err_free_stats:
> - kfree(clt_path->stats);
> err_free_con:
> kfree(clt_path->s.con);
> err_free_path:
> @@ -2863,7 +2857,6 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,
> list_del_rcu(&clt_path->s.entry);
> rtrs_clt_close_conns(clt_path, true);
> free_percpu(clt_path->stats->pcpu_stats);
> - kfree(clt_path->stats);
> free_path(clt_path);
> goto close_all_path;
> }
> @@ -2873,7 +2866,6 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,
> list_del_rcu(&clt_path->s.entry);
> rtrs_clt_close_conns(clt_path, true);
> free_percpu(clt_path->stats->pcpu_stats);
> - kfree(clt_path->stats);
> free_path(clt_path);
> goto close_all_path;
> }
> @@ -3166,7 +3158,6 @@ int rtrs_clt_create_path_from_sysfs(struct rtrs_clt_sess *clt,
> rtrs_clt_remove_path_from_arr(clt_path);
> rtrs_clt_close_conns(clt_path, true);
> free_percpu(clt_path->stats->pcpu_stats);
> - kfree(clt_path->stats);
> free_path(clt_path);
>
> return err;
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.h b/drivers/infiniband/ulp/rtrs/rtrs-clt.h
> index 986239ed2d3b..1305601a6251 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.h
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.h
> @@ -142,12 +142,12 @@ struct rtrs_clt_path {
> u32 flags;
> struct kobject kobj;
> u8 for_new_clt;
> - struct rtrs_clt_stats *stats;
> /* cache hca_port and hca_name to display in sysfs */
> u8 hca_port;
> char hca_name[IB_DEVICE_NAME_MAX];
> struct list_head __percpu
> *mp_skip_entry;
> + struct rtrs_clt_stats stats[];
> };
>
> struct rtrs_clt_sess {
> --
> 2.54.0
>
© 2016 - 2026 Red Hat, Inc.