On Wed, Oct 07, 2020 at 07:36:27PM -0700, Joe Perches wrote: > diff --git a/drivers/infiniband/hw/mlx4/sysfs.c b/drivers/infiniband/hw/mlx4/sysfs.c > index 75d50383da89..fc6c98b608d3 100644 > +++ b/drivers/infiniband/hw/mlx4/sysfs.c > @@ -444,16 +444,17 @@ static ssize_t show_port_pkey(struct mlx4_port *p, struct port_attribute *attr, > { > struct port_table_attribute *tab_attr = > container_of(attr, struct port_table_attribute, attr); > - ssize_t ret = -ENODEV; > + int len; > + struct pkey_mgt *m = &p->dev->pkeys; > + u8 key = m->virt2phys_pkey[p->slave][p->port_num - 1][tab_attr->index]; > > - if (p->dev->pkeys.virt2phys_pkey[p->slave][p->port_num - 1][tab_attr->index] >= > - (p->dev->dev->caps.pkey_table_len[p->port_num])) > - ret = sprintf(buf, "none\n"); > + if (key >= p->dev->dev->caps.pkey_table_len[p->port_num]) > + len = sysfs_emit(buf, "none\n"); > else > - ret = sprintf(buf, "%d\n", > - p->dev->pkeys.virt2phys_pkey[p->slave] > - [p->port_num - 1][tab_attr->index]); > - return ret; > + len = sysfs_emit(buf, "%d\n", > + p->dev->pkeys.virt2phys_pkey[p->slave] > + [p->port_num - 1][tab_attr->index]); > + return len; > } This duplication of virt2phys_pkey can be simplified to: static ssize_t show_port_pkey(struct mlx4_port *p, struct port_attribute *attr, char *buf) { struct port_table_attribute *tab_attr = container_of(attr, struct port_table_attribute, attr); struct pkey_mgt *m = &p->dev->pkeys; u8 key = m->virt2phys_pkey[p->slave][p->port_num - 1][tab_attr->index]; if (key >= p->dev->dev->caps.pkey_table_len[p->port_num]) return sysfs_emit(buf, "none\n"); return sysfs_emit(buf, "%d\n", key); } (I adjusted it) Jason