Re: [PATCH v4 10/14] gunyah: sysfs: Add node to describe supported features

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

 



On Sun, 2022-10-02 at 16:30 -0700, Jeff Johnson wrote:
> On 9/29/2022 12:36 AM, Joe Perches wrote:
> > On Wed, 2022-09-28 at 12:56 -0700, Elliot Berman wrote:
> > > Add a sysfs node to list the features that the Gunyah hypervisor and
> > > Linux supports. For now, Linux support cspace (capability IDs) and
> > > message queues, so only report those..
> > []
> > > diff --git a/drivers/virt/gunyah/sysfs.c b/drivers/virt/gunyah/sysfs.c
> > []
> > > @@ -25,9 +25,24 @@ static ssize_t variant_show(struct kobject *kobj, struct kobj_attribute *attr, c
> > >   }
> > >   static struct kobj_attribute variant_attr = __ATTR_RO(variant);
> > >   
> > > +static ssize_t features_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
> > > +{
> > > +	int len = 0;
> > > +
> > > +	if (GH_IDENTIFY_PARTITION_CSPACE(gunyah_api.flags))
> > > +		len += sysfs_emit_at(buffer, len, "cspace ");
> > > +	if (GH_IDENTIFY_MSGQUEUE(gunyah_api.flags))
> > > +		len += sysfs_emit_at(buffer, len, "message-queue ");
> > > +
> > > +	len += sysfs_emit_at(buffer, len, "\n");
> > > +	return len;
> > > +}
> > 
> > It's generally nicer to avoid unnecessary output spaces.
> > 
> > Perhaps:
> > 
> > {
> > 	int len = 0;
> > 
> > 	if (GH_IDENTIFY_PARTITION_CSPACE(gunyah_api.flags))
> > 		len += sysfs_emit_at(buffer, len, "cspace");
> > 	if (GH_IDENTIFY_MSGQUEUE(gunyah_api.flags)) {
> > 		if (len)
> > 			len += sysfs_emit_at(buffer, len, " ");
> > 		len += sysfs_emit_at(buffer, len, "message-queue");
> > 	}
> > 
> > 	len += sysfs_emit_at(buffer, len, "\n");
> > 
> > 	return len;
> > }
> > 
> 
> that approach seems ok for 2 features, but imo doesn't scale for more.
> I like the original code with one exception:
> 
> 	if (GH_IDENTIFY_PARTITION_CSPACE(gunyah_api.flags))
> 		len += sysfs_emit_at(buffer, len, "cspace ");
> 	if (GH_IDENTIFY_MSGQUEUE(gunyah_api.flags))
> 		len += sysfs_emit_at(buffer, len, "message-queue ");
> 
> 	/* overwrite last trailing space */
> 	if (len)
> 		len--;
> 
> 	len += sysfs_emit_at(buffer, len, "\n");
> 	return len;
> 

That's fine as long as every formatted output uses a trailing space.

A trivial negative would be that the linker would generally not be
able to deduplicate these output strings with trailing spaces across
the entire codebase.




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [Linux for Sparc]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux