On Thu, Oct 8, 2020 at 4:36 AM Joe Perches <joe@xxxxxxxxxxx> wrote: > > Make changes to use sysfs_emit in the RDMA code as cocci scripts can not > be written to handle _all_ the possible variants of various sprintf family > uses in sysfs show functions. > > While there, make the code more legible and update its style to be more > like the typical kernel styles. > > Miscellanea: > > o Use intermediate pointers for dereferences > o Add and use string lookup functions > o return early when any intermediate call fails so normal return is > at the bottom of the function > o mlx4/mcg.c:sysfs_show_group: use scnprintf to format intermediate strings > > Signed-off-by: Joe Perches <joe@xxxxxxxxxxx> > --- > drivers/infiniband/core/sysfs.c | 60 +++++++------- > drivers/infiniband/hw/cxgb4/provider.c | 5 +- > drivers/infiniband/hw/hfi1/sysfs.c | 38 ++++----- > drivers/infiniband/hw/mlx4/main.c | 5 +- > drivers/infiniband/hw/mlx4/mcg.c | 82 +++++++++++--------- > drivers/infiniband/hw/mlx4/sysfs.c | 47 ++++++----- > drivers/infiniband/hw/mlx5/main.c | 4 +- > drivers/infiniband/hw/mthca/mthca_provider.c | 29 ++++--- > drivers/infiniband/hw/qib/qib_sysfs.c | 45 +++++------ > drivers/infiniband/hw/usnic/usnic_ib_sysfs.c | 66 +++++++--------- > drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 21 +++-- > drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c | 13 ++-- > drivers/infiniband/ulp/srp/ib_srp.c | 4 + > 13 files changed, 206 insertions(+), 213 deletions(-) > > > diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c > index 0c767582286b..51ba82fc425c 100644 > --- a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c > +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c > @@ -196,11 +196,10 @@ static struct kobj_attribute rtrs_clt_state_attr = > __ATTR(state, 0444, rtrs_clt_state_show, NULL); > > static ssize_t rtrs_clt_reconnect_show(struct kobject *kobj, > - struct kobj_attribute *attr, > - char *buf) > + struct kobj_attribute *attr, > + char *buf) > { > - return sysfs_emit(buf, "Usage: echo 1 > %s\n", > - attr->attr.name); > + return sysfs_emit(buf, "Usage: echo 1 > %s\n", attr->attr.name); > } > > static ssize_t rtrs_clt_reconnect_store(struct kobject *kobj, > @@ -228,11 +227,10 @@ static struct kobj_attribute rtrs_clt_reconnect_attr = > rtrs_clt_reconnect_store); > > static ssize_t rtrs_clt_disconnect_show(struct kobject *kobj, > - struct kobj_attribute *attr, > - char *buf) > + struct kobj_attribute *attr, > + char *buf) > { > - return sysfs_emit(buf, "Usage: echo 1 > %s\n", > - attr->attr.name); > + return sysfs_emit(buf, "Usage: echo 1 > %s\n", attr->attr.name); > } > > static ssize_t rtrs_clt_disconnect_store(struct kobject *kobj, > @@ -260,11 +258,10 @@ static struct kobj_attribute rtrs_clt_disconnect_attr = > rtrs_clt_disconnect_store); > > static ssize_t rtrs_clt_remove_path_show(struct kobject *kobj, > - struct kobj_attribute *attr, > - char *buf) > + struct kobj_attribute *attr, > + char *buf) > { > - return sysfs_emit(buf, "Usage: echo 1 > %s\n", > - attr->attr.name); > + return sysfs_emit(buf, "Usage: echo 1 > %s\n", attr->attr.name); > } > > static ssize_t rtrs_clt_remove_path_store(struct kobject *kobj, > diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c > index 381a776ce404..6e7bebe4e064 100644 > --- a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c > +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c > @@ -27,11 +27,10 @@ static struct kobj_type ktype = { > }; > > static ssize_t rtrs_srv_disconnect_show(struct kobject *kobj, > - struct kobj_attribute *attr, > - char *buf) > + struct kobj_attribute *attr, > + char *buf) > { > - return sysfs_emit(buf, "Usage: echo 1 > %s\n", > - attr->attr.name); > + return sysfs_emit(buf, "Usage: echo 1 > %s\n", attr->attr.name); > } > > static ssize_t rtrs_srv_disconnect_store(struct kobject *kobj, > @@ -72,8 +71,7 @@ static ssize_t rtrs_srv_hca_port_show(struct kobject *kobj, > sess = container_of(kobj, typeof(*sess), kobj); > usr_con = sess->s.con[0]; > > - return sysfs_emit(page, "%u\n", > - usr_con->cm_id->port_num); > + return sysfs_emit(page, "%u\n", usr_con->cm_id->port_num); > } > > static struct kobj_attribute rtrs_srv_hca_port_attr = > @@ -87,8 +85,7 @@ static ssize_t rtrs_srv_hca_name_show(struct kobject *kobj, > > sess = container_of(kobj, struct rtrs_srv_sess, kobj); > > - return sysfs_emit(page, "%s\n", > - sess->s.dev->ib_dev->name); > + return sysfs_emit(page, "%s\n", sess->s.dev->ib_dev->name); > } > For rtrs, looks good to me! Thanks, Acked-by: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx>