Re: [PATCH 3/4] RDMA: manual changes for sysfs_emit and neatening

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

 



On Wed, 2020-10-28 at 10:54 -0700, Joe Perches wrote:
> On Wed, 2020-10-28 at 14:25 -0300, Jason Gunthorpe wrote:
> > On Wed, Oct 07, 2020 at 07:36:26PM -0700, Joe Perches wrote:
> > 
> > > @@ -653,10 +651,7 @@ static ssize_t serial_show(struct device *device,
> > >  		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
> > >  	struct qib_devdata *dd = dd_from_dev(dev);
> > >  
> > > 
> > > -	buf[sizeof(dd->serial)] = '\0';
> > > -	memcpy(buf, dd->serial, sizeof(dd->serial));
> > > -	strcat(buf, "\n");
> > > -	return strlen(buf);
> > > +	return sysfs_emit(buf, "%s\n", dd->serial);
> > >  }
> > 
> > This is not the same thing? dd->serial does not look null terminated,
> > eg it is filled like this:
> > 
> > 		memcpy(dd->serial, ifp->if_serial, sizeof(ifp->if_serial));
> > 
> > From data read off the flash
> 
> It seems you are correct.
> 
> Maybe instead:
> ---
> static ssize_t serial_show(struct device *device,
> 			   struct device_attribute *attr, char *buf)
> {
> 	struct qib_ibdev *dev =
> 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
> 	struct qib_devdata *dd = dd_from_dev(dev);
> 	const u8 *end = memchr(dd->serial, 0, ARRAY_SIZE(dd->serial));
> 	int size = end ? end - dd->serial : ARRAY_SIZE(dd->serial);
> 
> 	return sysfs_emit(buf, "%*s\n", size, dd->serial);

I believe for this to actually be correct, this should be:

	return sysfs_emit(buf, "%.*s\n", size, dd->serial);





[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