Re: [PATCH 4/4] RDMA: Convert various random sprintf sysfs _show uses to sysfs_emit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2020-10-28 at 15:12 -0300, Jason Gunthorpe wrote:
> 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
[]
> > @@ -444,16 +444,17 @@ static ssize_t show_port_pkey(struct mlx4_port *p, struct port_attribute *attr,
> >  {
[]
> > +	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)

Thanks, it seems better without using the len automatic too.





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux