[PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions.

Dan Carpenter dan.carpenter at oracle.com
Fri Nov 9 17:15:58 UTC 2018


On Wed, Nov 07, 2018 at 10:30:43AM +0800, Jerry Lin wrote:
> Add a attribute called permissions under vsoc device node for examining
> current granted permissions in vsoc_device.
> 
> This file will display permissions in following format:
>   begin_offset  end_offset  owner_offset  owned_value
>             %x          %x            %x           %x
> 

(I'm not totally an expert on sysfs rules).

Sysfs are supposed to be one value per file, so instead of doing this
you would create a directory with four files like
vsoc_device/begin_offset vsoc_device/end_offset etc.  And each would
just hae a %x output.

> +static ssize_t permissions_show(struct device *dev,
> +				struct device_attribute *attr,
> +				char *buffer)
> +{
> +	struct fd_scoped_permission_node *node;
> +	char *row;
> +	int ret;
> +	ssize_t written = 0;
> +
> +	row = kzalloc(sizeof(char) * 128, GFP_KERNEL);
> +	if (!row)
> +		return 0;

Don't allocate this, just snprintf() directly into the buffer.

regards,
dan carpenter



More information about the devel mailing list