All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Doug Ledford <dledford@redhat.com>,
	Mike Marciniszyn <mike.marciniszyn@intel.com>,
	Dennis Dalessandro <dennis.dalessandro@intel.com>,
	Yishai Hadas <yishaih@nvidia.com>,
	Christian Benvenuti <benve@cisco.com>,
	Nelson Escobar <neescoba@cisco.com>,
	Parvi Kaustubhi <pkaustub@cisco.com>,
	Danil Kipnis <danil.kipnis@cloud.ionos.com>,
	Jack Wang <jinpu.wang@cloud.ionos.com>,
	Bart Van Assche <bvanassche@acm.org>,
	linux-rdma@vger.kernel.org
Subject: Re: [PATCH 4/4] RDMA: Convert various random sprintf sysfs _show uses to sysfs_emit
Date: Wed, 28 Oct 2020 11:22:08 -0700	[thread overview]
Message-ID: <e0adf52646f1206747a3087fd59edc748ba9b208.camel@perches.com> (raw)
In-Reply-To: <20201028181201.GA2468498@nvidia.com>

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.



  reply	other threads:[~2020-10-29  1:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08  2:36 [PATCH-next 0/4] RDMA: sprintf to sysfs_emit conversions Joe Perches
2020-10-08  2:36 ` Joe Perches
2020-10-08  2:36 ` [PATCH 1/4] RDMA: Convert sysfs device * show functions to use sysfs_emit() Joe Perches
2020-10-09 14:07   ` Jason Gunthorpe
2020-10-08  2:36 ` [PATCH 2/4] RDMA: Convert sysfs kobject " Joe Perches
2020-10-09 14:09   ` Jason Gunthorpe
2020-10-09 16:25     ` Joe Perches
2020-10-12  5:21   ` Jinpu Wang
2020-10-08  2:36 ` [PATCH 3/4] RDMA: manual changes for sysfs_emit and neatening Joe Perches
2020-10-09 15:20   ` Jason Gunthorpe
2020-10-12  5:30   ` Jinpu Wang
2020-10-28 17:25   ` Jason Gunthorpe
2020-10-28 17:54     ` Joe Perches
2020-10-28 18:23       ` Jason Gunthorpe
2020-10-29 17:16       ` Joe Perches
2020-10-31  0:04         ` Jason Gunthorpe
2020-10-08  2:36 ` [PATCH 4/4] RDMA: Convert various random sprintf sysfs _show uses to sysfs_emit Joe Perches
2020-10-09 15:27   ` Jason Gunthorpe
2020-10-12  5:25   ` Jinpu Wang
2020-10-28 18:12   ` Jason Gunthorpe
2020-10-28 18:22     ` Joe Perches [this message]
2020-10-08  5:41 ` [PATCH-next 0/4] RDMA: sprintf to sysfs_emit conversions Leon Romanovsky
2020-10-08  5:41   ` Leon Romanovsky
2020-10-08  5:52   ` Joe Perches
2020-10-08  5:52     ` Joe Perches
2020-10-08  7:02     ` Leon Romanovsky
2020-10-08  7:02       ` Leon Romanovsky
2020-10-15  5:29   ` Joe Perches
2020-10-15  5:29     ` Joe Perches
2020-10-26 22:54 ` Jason Gunthorpe
2020-10-26 22:54   ` Jason Gunthorpe
2020-10-28 18:27 ` Jason Gunthorpe
2020-10-28 18:27   ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e0adf52646f1206747a3087fd59edc748ba9b208.camel@perches.com \
    --to=joe@perches.com \
    --cc=benve@cisco.com \
    --cc=bvanassche@acm.org \
    --cc=danil.kipnis@cloud.ionos.com \
    --cc=dennis.dalessandro@intel.com \
    --cc=dledford@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mike.marciniszyn@intel.com \
    --cc=neescoba@cisco.com \
    --cc=pkaustub@cisco.com \
    --cc=yishaih@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.