Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1254139 > unrolled thread
| Started by | Pantelis Antoniou <pantelis.antoniou@konsulko.com> |
|---|---|
| First post | 2015-10-22 22:00 +0200 |
| Last post | 2015-10-22 22:40 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v7 2/6] of: overlay: global sysfs enable attribute Pantelis Antoniou <pantelis.antoniou@konsulko.com> - 2015-10-22 22:00 +0200
Re: [PATCH v7 2/6] of: overlay: global sysfs enable attribute Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-10-22 22:20 +0200
Re: [PATCH v7 2/6] of: overlay: global sysfs enable attribute Pantelis Antoniou <panto@antoniou-consulting.com> - 2015-10-22 22:40 +0200
| From | Pantelis Antoniou <pantelis.antoniou@konsulko.com> |
|---|---|
| Date | 2015-10-22 22:00 +0200 |
| Subject | [PATCH v7 2/6] of: overlay: global sysfs enable attribute |
| Message-ID | <qmubM-43S-5@gated-at.bofh.it> |
A throw once master enable switch to protect against any
further overlay applications if the administrator desires so.
A kernel command line option is provided as well.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
drivers/of/overlay.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 12c3e47..91f10ed 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -21,6 +21,7 @@
#include <linux/err.h>
#include <linux/idr.h>
#include <linux/sysfs.h>
+#include <linux/atomic.h>
#include "of_private.h"
@@ -55,8 +56,19 @@ struct of_overlay {
struct kobject kobj;
};
+/* master enable switch; once set to 0 can't be re-enabled */
+static atomic_t ov_enable = ATOMIC_INIT(1);
+
+static int __init of_overlay_disable_setup(char *str __always_unused)
+{
+ atomic_set(&ov_enable, 0);
+ return 1;
+}
+__setup("of_overlay_disable", of_overlay_disable_setup);
+
static int of_overlay_apply_one(struct of_overlay *ov,
struct device_node *target, const struct device_node *overlay);
+static int overlay_removal_is_ok(struct of_overlay *ov);
static int of_overlay_apply_single_property(struct of_overlay *ov,
struct device_node *target, struct property *prop)
@@ -339,6 +351,35 @@ void of_overlay_release(struct kobject *kobj)
kfree(ov);
}
+static ssize_t enable_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&ov_enable));
+}
+
+static ssize_t enable_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ int ret;
+ bool new_enable;
+
+ ret = strtobool(buf, &new_enable);
+ if (ret != 0)
+ return ret;
+ /* if we've disabled it, no going back */
+ if (atomic_read(&ov_enable) == 0)
+ return -EPERM;
+ atomic_set(&ov_enable, (int)new_enable);
+ return count;
+}
+
+static struct kobj_attribute enable_attr = __ATTR_RW(enable);
+
+static const struct attribute *overlay_global_attrs[] = {
+ &enable_attr.attr,
+ NULL
+};
+
static struct kobj_type of_overlay_ktype = {
.release = of_overlay_release,
};
@@ -360,6 +401,10 @@ int of_overlay_create(struct device_node *tree)
struct of_overlay *ov;
int err, id;
+ /* administratively disabled */
+ if (!atomic_read(&ov_enable))
+ return -EPERM;
+
/* allocate the overlay structure */
ov = kzalloc(sizeof(*ov), GFP_KERNEL);
if (ov == NULL)
@@ -594,5 +639,8 @@ int of_overlay_init(void)
if (!ov_kset)
return -ENOMEM;
- return 0;
+ rc = sysfs_create_files(&ov_kset->kobj, overlay_global_attrs);
+ WARN(rc, "%s: error adding global attributes\n", __func__);
+
+ return rc;
}
--
1.7.12
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2015-10-22 22:20 +0200 |
| Message-ID | <qmuv8-4FS-9@gated-at.bofh.it> |
| In reply to | #1254139 |
On Thu, Oct 22, 2015 at 10:50:23PM +0300, Pantelis Antoniou wrote:
> A throw once master enable switch to protect against any
> further overlay applications if the administrator desires so.
>
> A kernel command line option is provided as well.
>
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
> drivers/of/overlay.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index 12c3e47..91f10ed 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -21,6 +21,7 @@
> #include <linux/err.h>
> #include <linux/idr.h>
> #include <linux/sysfs.h>
> +#include <linux/atomic.h>
>
> #include "of_private.h"
>
> @@ -55,8 +56,19 @@ struct of_overlay {
> struct kobject kobj;
> };
>
> +/* master enable switch; once set to 0 can't be re-enabled */
> +static atomic_t ov_enable = ATOMIC_INIT(1);
> +
> +static int __init of_overlay_disable_setup(char *str __always_unused)
> +{
> + atomic_set(&ov_enable, 0);
> + return 1;
> +}
> +__setup("of_overlay_disable", of_overlay_disable_setup);
> +
> static int of_overlay_apply_one(struct of_overlay *ov,
> struct device_node *target, const struct device_node *overlay);
> +static int overlay_removal_is_ok(struct of_overlay *ov);
>
> static int of_overlay_apply_single_property(struct of_overlay *ov,
> struct device_node *target, struct property *prop)
> @@ -339,6 +351,35 @@ void of_overlay_release(struct kobject *kobj)
> kfree(ov);
> }
>
> +static ssize_t enable_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&ov_enable));
Minor nit, you never need to care about the size of the buffer for a
sysfs file, if you do, you are doing something wrong. So this can just
be:
return sprintf(buf, "%d\n", atomic_read(&ov_enable));
Anyway, nothing worth keeping this from being merged:
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Pantelis Antoniou <panto@antoniou-consulting.com> |
|---|---|
| Date | 2015-10-22 22:40 +0200 |
| Message-ID | <qmuOu-537-17@gated-at.bofh.it> |
| In reply to | #1254154 |
Hi Greg,
> On Oct 22, 2015, at 23:19 , Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Oct 22, 2015 at 10:50:23PM +0300, Pantelis Antoniou wrote:
>> A throw once master enable switch to protect against any
>> further overlay applications if the administrator desires so.
>>
>> A kernel command line option is provided as well.
>>
>> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
>> ---
>> drivers/of/overlay.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 49 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
>> index 12c3e47..91f10ed 100644
>> --- a/drivers/of/overlay.c
>> +++ b/drivers/of/overlay.c
>> @@ -21,6 +21,7 @@
>> #include <linux/err.h>
>> #include <linux/idr.h>
>> #include <linux/sysfs.h>
>> +#include <linux/atomic.h>
>>
>> #include "of_private.h"
>>
>> @@ -55,8 +56,19 @@ struct of_overlay {
>> struct kobject kobj;
>> };
>>
>> +/* master enable switch; once set to 0 can't be re-enabled */
>> +static atomic_t ov_enable = ATOMIC_INIT(1);
>> +
>> +static int __init of_overlay_disable_setup(char *str __always_unused)
>> +{
>> + atomic_set(&ov_enable, 0);
>> + return 1;
>> +}
>> +__setup("of_overlay_disable", of_overlay_disable_setup);
>> +
>> static int of_overlay_apply_one(struct of_overlay *ov,
>> struct device_node *target, const struct device_node *overlay);
>> +static int overlay_removal_is_ok(struct of_overlay *ov);
>>
>> static int of_overlay_apply_single_property(struct of_overlay *ov,
>> struct device_node *target, struct property *prop)
>> @@ -339,6 +351,35 @@ void of_overlay_release(struct kobject *kobj)
>> kfree(ov);
>> }
>>
>> +static ssize_t enable_show(struct kobject *kobj,
>> + struct kobj_attribute *attr, char *buf)
>> +{
>> + return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&ov_enable));
>
> Minor nit, you never need to care about the size of the buffer for a
> sysfs file, if you do, you are doing something wrong. So this can just
> be:
> return sprintf(buf, "%d\n", atomic_read(&ov_enable));
>
>
Nice to know; I have a ingrained habit to avoid standard sprintf, so..
> Anyway, nothing worth keeping this from being merged:
>
Thanks!
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>
Regards
— Pantelis
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web