From: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
To: Rob Herring <robherring2@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Frank Rowand <frowand.list@gmail.com>,
Matt Porter <mporter@konsulko.com>,
Koen Kooi <koen@dominion.thruhere.net>,
Guenter Roeck <linux@roeck-us.net>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>
Subject: Re: [PATCH v6 2/4] of: overlay: global sysfs enable attribute
Date: Wed, 21 Oct 2015 11:47:05 +0300 [thread overview]
Message-ID: <239C2ADB-C80E-40BF-9FED-BC61CF496AF1@konsulko.com> (raw)
In-Reply-To: <CAL_JsqLxvO4ke79rbBvq2ybPDeXdFtL+_Y4G9uFbz19eeSp3vg@mail.gmail.com>
Hi Rob,
> On Oct 21, 2015, at 00:50 , Rob Herring <robherring2@gmail.com> wrote:
>
> On Tue, Oct 20, 2015 at 4:06 PM, Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
>> On Tue, Oct 20, 2015 at 10:13:15PM +0300, Pantelis Antoniou wrote:
>>> A throw once master enable switch to protect against any
>>> further overlay applications if the administrator desires so.
>>>
>>> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
>>> ---
>>> drivers/of/overlay.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
>>> 1 file changed, 42 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
>>> index 12c3e47..067404e 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,12 @@ 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 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 +344,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 +394,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 +632,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;
>>> }
>>
>> Shouldn't this also be allowed to be overridden as a boot and build time
>> parameter to prevent any races on systems that don't want this?
>
> Build time is already there to disable overlays. A command line option
> would be good though.
>
No problemo. I’ll include it in the next version to go out today.
> Rob
Regards
— Pantelis
next prev parent reply other threads:[~2015-10-21 8:47 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-20 19:13 [PATCH v6 0/4] of: overlay: kobject & sysfs'ation Pantelis Antoniou
2015-10-20 19:13 ` [PATCH v6 1/4] of: overlay: kobjectify overlay objects Pantelis Antoniou
2015-10-20 21:03 ` Greg Kroah-Hartman
2015-10-21 13:28 ` Pantelis Antoniou
2015-10-21 15:22 ` Greg Kroah-Hartman
2015-10-20 19:13 ` [PATCH v6 2/4] of: overlay: global sysfs enable attribute Pantelis Antoniou
2015-10-20 21:06 ` Greg Kroah-Hartman
2015-10-20 21:50 ` Rob Herring
2015-10-21 8:47 ` Pantelis Antoniou [this message]
2015-10-20 19:13 ` [PATCH v6 3/4] of: overlay: add per overlay sysfs attributes Pantelis Antoniou
2015-10-20 21:04 ` Rob Herring
2015-10-20 21:11 ` Pantelis Antoniou
2015-10-20 21:54 ` Rob Herring
2015-10-21 19:37 ` Pantelis Antoniou
2015-10-21 21:52 ` Rob Herring
2015-10-22 16:15 ` Pantelis Antoniou
2015-11-05 19:52 ` Rob Herring
2015-11-05 20:17 ` Pantelis Antoniou
2015-10-20 21:08 ` Greg Kroah-Hartman
2015-10-20 21:15 ` Pantelis Antoniou
2015-10-20 23:25 ` Greg Kroah-Hartman
2015-10-20 19:13 ` [PATCH v6 4/4] Documentation: ABI: /sys/firmware/devicetree/overlays Pantelis Antoniou
2015-10-20 20:56 ` Rob Herring
2015-10-20 21:02 ` Pantelis Antoniou
2015-10-20 22:00 ` Rob Herring
2015-10-20 21:06 ` [PATCH v6 0/4] of: overlay: kobject & sysfs'ation Rob Herring
2015-10-20 21:11 ` Pantelis Antoniou
2015-10-20 21:52 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=239C2ADB-C80E-40BF-9FED-BC61CF496AF1@konsulko.com \
--to=pantelis.antoniou@konsulko.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=koen@dominion.thruhere.net \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mporter@konsulko.com \
--cc=robherring2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®