* [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions.
@ 2018-11-07 2:30 Jerry Lin
2018-11-07 9:15 ` Greg Kroah-Hartman
2018-11-09 17:15 ` Dan Carpenter
0 siblings, 2 replies; 8+ messages in thread
From: Jerry Lin @ 2018-11-07 2:30 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, astrachan, ghartman, linux-kernel, devel
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
Signed-off-by: Jerry Lin <wahahab11@gmail.com>
---
drivers/staging/android/vsoc.c | 48 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c
index 22571ab..8ce3604 100644
--- a/drivers/staging/android/vsoc.c
+++ b/drivers/staging/android/vsoc.c
@@ -128,9 +128,10 @@ struct vsoc_device {
static struct vsoc_device vsoc_dev;
-/*
- * TODO(ghartman): Add a /sys filesystem entry that summarizes the permissions.
- */
+static ssize_t permissions_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf);
+static DEVICE_ATTR_RO(permissions);
struct fd_scoped_permission_node {
struct fd_scoped_permission permission;
@@ -718,6 +719,37 @@ static ssize_t vsoc_write(struct file *filp, const char __user *buffer,
return len;
}
+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;
+ mutex_lock(&vsoc_dev.mtx);
+ list_for_each_entry(node, &vsoc_dev.permissions, list) {
+ ret = snprintf(row, 128, "%x\t%x\t%x\t%x\n",
+ node->permission.begin_offset,
+ node->permission.end_offset,
+ node->permission.owner_offset,
+ node->permission.owned_value);
+ if (ret < 0)
+ goto done;
+ memcpy(buffer + written, row, ret);
+ written += ret;
+ }
+
+done:
+ mutex_unlock(&vsoc_dev.mtx);
+ kfree(row);
+ return written;
+}
+
static irqreturn_t vsoc_interrupt(int irq, void *region_data_v)
{
struct vsoc_region_data *region_data =
@@ -942,6 +974,15 @@ static int vsoc_probe_device(struct pci_dev *pdev,
}
vsoc_dev.regions_data[i].device_created = true;
}
+ /*
+ * Create permission attribute on device node.
+ */
+ result = device_create_file(&pdev->dev, &dev_attr_permissions);
+ if (result) {
+ dev_err(&vsoc_dev.dev->dev, "device_create_file failed\n");
+ vsoc_remove_device(pdev);
+ return -EFAULT;
+ }
return 0;
}
@@ -967,6 +1008,7 @@ static void vsoc_remove_device(struct pci_dev *pdev)
if (!pdev || !vsoc_dev.dev)
return;
dev_info(&pdev->dev, "remove_device\n");
+ device_remove_file(&pdev->dev, &dev_attr_permissions);
if (vsoc_dev.regions_data) {
for (i = 0; i < vsoc_dev.layout->region_count; ++i) {
if (vsoc_dev.regions_data[i].device_created) {
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions.
2018-11-07 2:30 [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions Jerry Lin
@ 2018-11-07 9:15 ` Greg Kroah-Hartman
2018-11-08 0:49 ` wahahab
2018-11-09 17:15 ` Dan Carpenter
1 sibling, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-07 9:15 UTC (permalink / raw)
To: Jerry Lin
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, astrachan, ghartman, linux-kernel, devel
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
>
> Signed-off-by: Jerry Lin <wahahab11@gmail.com>
> ---
> drivers/staging/android/vsoc.c | 48 +++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 45 insertions(+), 3 deletions(-)
What changed from v2? And where was v2? What about v1?
You need a change log here of what you did different from the previous
patches.
And why ignore my response saying that this type of sysfs file is not ok
at all?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions.
2018-11-07 9:15 ` Greg Kroah-Hartman
@ 2018-11-08 0:49 ` wahahab
2018-11-08 1:44 ` Greg Kroah-Hartman
0 siblings, 1 reply; 8+ messages in thread
From: wahahab @ 2018-11-08 0:49 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, astrachan, ghartman, linux-kernel, devel
> On 7 Nov 2018, at 5:15 PM, Greg Kroah-Hartman <greg@kroah.com> wrote:
>
> 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
>>
>> Signed-off-by: Jerry Lin <wahahab11@gmail.com>
>> ---
>> drivers/staging/android/vsoc.c | 48 +++++++++++++++++++++++++++++++++++++++---
>> 1 file changed, 45 insertions(+), 3 deletions(-)
>
> What changed from v2? And where was v2? What about v1?
>
> You need a change log here of what you did different from the previous
> patches.
Sorry for the mistakes I made, I shall read the document about patches more carefully.
Here is the change logs:
Changes in v2:
- Display permissions information in sysfs insureds of debufs.
Changes in v3:
- Remove unnecessary null terminator after snprintf.
>
> And why ignore my response saying that this type of sysfs file is not ok
> at all?
>
I didn’t mean to ignore it but I haven’t receive the response you described,
May you send the response to me again so I can do further revision as well as
change logs and resubmit the patch again?
Thanks for your patience
Jerry
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions.
2018-11-08 0:49 ` wahahab
@ 2018-11-08 1:44 ` Greg Kroah-Hartman
0 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-08 1:44 UTC (permalink / raw)
To: wahahab
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, astrachan, ghartman, linux-kernel, devel
On Thu, Nov 08, 2018 at 08:49:41AM +0800, wahahab wrote:
>
> > On 7 Nov 2018, at 5:15 PM, Greg Kroah-Hartman <greg@kroah.com> wrote:
> >
> > 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
> >>
> >> Signed-off-by: Jerry Lin <wahahab11@gmail.com>
> >> ---
> >> drivers/staging/android/vsoc.c | 48 +++++++++++++++++++++++++++++++++++++++---
> >> 1 file changed, 45 insertions(+), 3 deletions(-)
> >
> > What changed from v2? And where was v2? What about v1?
> >
> > You need a change log here of what you did different from the previous
> > patches.
>
> Sorry for the mistakes I made, I shall read the document about patches more carefully.
> Here is the change logs:
>
> Changes in v2:
> - Display permissions information in sysfs insureds of debufs.
> Changes in v3:
> - Remove unnecessary null terminator after snprintf.
>
> >
> > And why ignore my response saying that this type of sysfs file is not ok
> > at all?
> >
>
> I didn’t mean to ignore it but I haven’t receive the response you described,
> May you send the response to me again so I can do further revision as well as
> change logs and resubmit the patch again?
You can not have multiple values in a single sysfs file. sysfs is "one
value per file". This needs to be individual files, if you really need
this. And never a "header" for a sysfs file, that's never something
that should ever be in a sysfs file.
And finally, you need a Documentation/ABI/ update for any sysfs file
changes.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions.
2018-11-07 2:30 [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions Jerry Lin
2018-11-07 9:15 ` Greg Kroah-Hartman
@ 2018-11-09 17:15 ` Dan Carpenter
[not found] ` <6ADC007E-85BB-4CA1-89FB-9254937E8C63@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2018-11-09 17:15 UTC (permalink / raw)
To: Jerry Lin
Cc: Greg Kroah-Hartman, devel, Todd Kjos, ghartman, astrachan,
linux-kernel, Arve Hjønnevåg, Joel Fernandes,
Martijn Coenen
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-11-20 9:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-07 2:30 [PATCH v3] driver-staging: vsoc.c: Add sysfs support for examining the permissions of regions Jerry Lin
2018-11-07 9:15 ` Greg Kroah-Hartman
2018-11-08 0:49 ` wahahab
2018-11-08 1:44 ` Greg Kroah-Hartman
2018-11-09 17:15 ` Dan Carpenter
[not found] ` <6ADC007E-85BB-4CA1-89FB-9254937E8C63@gmail.com>
2018-11-12 12:40 ` Greg Kroah-Hartman
2018-11-13 3:32 ` wahahab
2018-11-20 9:56 ` Greg Kroah-Hartman
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.