[PATCH] NVMe:Expose model attribute in sysfs

Sujith Pandel sujithpshankar at gmail.com
Tue Sep 1 09:38:58 PDT 2015


On Tue, Aug 25, 2015 at 10:38:54AM -0500, Matthew Wilcox wrote:
> > @@ -2360,6 +2360,7 @@ static int nvme_dev_add(struct nvme_dev *dev)
> >  	memcpy(dev->model, ctrl->mn, sizeof(ctrl->mn));
> > +	dev->model[sizeof(ctrl->mn) - 1] = '\0';
> >  	memcpy(dev->firmware_rev, ctrl->fr, sizeof(ctrl->fr));
> 
> You've overwritten the last byte of the model name with a NUL byte.  There
> could be useful information in that byte.

Agree with you on this. I will remove that statement.

> > +static ssize_t nvme_sysfs_model(struct device *dev,
> > +				struct device_attribute *attr, char *buf)
> > +{
> > +	struct nvme_dev *ndev = dev_get_drvdata(dev);
> > +
> > +	return sprintf(buf, "%s\n", ndev->model);
> 
> Instead, how about:
> 
> 	return sprintf(buf, "%.40s\n", ndev->model);

Can we use:
	return sprintf(buf, "%.*s\n", (int)sizeof(ndev->model), ndev->model); 

This way we need not hard-code the model attribute size in it.
Please let me know your thoughts on this.

Regards,
Sujith



More information about the Linux-nvme mailing list