mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "Bharathi, Divya" <Divya.Bharathi@Dell.com>,
	Divya Bharathi <divya27392@gmail.com>,
	"dvhart@infradead.org" <dvhart@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	"platform-driver-x86@vger.kernel.org" 
	<platform-driver-x86@vger.kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	mark gross <mgross@linux.intel.com>,
	"Limonciello, Mario" <Mario.Limonciello@dell.com>,
	"Ksr, Prasanth" <Prasanth.Ksr@dell.com>
Subject: Re: [PATCH v5] Introduce support for Systems Management Driver over WMI for Dell Systems
Date: Fri, 9 Oct 2020 09:58:22 +0200	[thread overview]
Message-ID: <a7cc8b62-c87a-2253-de7a-7b463589ee4c@redhat.com> (raw)
In-Reply-To: <CY4PR19MB125486920AE0C6CA105B973A850D0@CY4PR19MB1254.namprd19.prod.outlook.com>

HI,

On 10/6/20 10:46 AM, Bharathi, Divya wrote:
> Sorry for another mail on same patch. I missed to add one response on
> previous comments

No problem.

> <snip>
> 
>>> +/**
>>> + * init_bios_attributes() - Initialize all attributes for a type
>>> + * @attr_type: The attribute type to initialize
>>> + * @guid: The WMI GUID associated with this type to initialize
>>> + *
>>> + * Initialiaze all 4 types of attributes enumeration, integer, string and
>> password object.
>>> + * Populates each attrbute typ's respective properties under sysfs files
>>> + **/
>>> +static int init_bios_attributes(int attr_type, const char *guid)
>>> +{
>>> +	struct kobject *attr_name_kobj; //individual attribute names
>>> +	union acpi_object *obj = NULL;
>>> +	union acpi_object *elements;
>>> +	struct kset *tmp_set;
>>> +
>>> +	/* instance_id needs to be reset for each type GUID
>>> +	 * also, instance IDs are unique within GUID but not across
>>> +	 */
>>> +	int instance_id = 0;
>>> +	int retval = 0;
>>> +
>>> +	retval = alloc_attributes_data(attr_type);
>>> +	if (retval)
>>> +		return retval;
>>> +	/* need to use specific instance_id and guid combination to get right
>> data */
>>> +	obj = get_wmiobj_pointer(instance_id, guid);
>>> +	if (!obj)
>>> +		return -ENODEV;
>>> +	elements = obj->package.elements;
>>> +
>>> +	mutex_lock(&wmi_priv.mutex);
>>> +	while (elements) {
>>> +		/* sanity checking */
>>> +		if (strlen(elements[ATTR_NAME].string.pointer) == 0) {
>>> +			pr_debug("empty attribute found\n");
>>> +			goto nextobj;
>>> +		}
>>> +		if (attr_type == PO)
>>> +			tmp_set = wmi_priv.authentication_dir_kset;
>>> +		else
>>> +			tmp_set = wmi_priv.main_dir_kset;
>>> +
>>> +		if (kset_find_obj(tmp_set,
>> elements[ATTR_NAME].string.pointer)) {
>>> +			pr_debug("duplicate attribute name found - %s\n",
>>> +				elements[ATTR_NAME].string.pointer);
>>> +			goto nextobj;
>>> +		}
>>> +
>>> +		/* build attribute */
>>> +		attr_name_kobj = kzalloc(sizeof(*attr_name_kobj),
>> GFP_KERNEL);
>>> +		if (!attr_name_kobj)
>>> +			goto err_attr_init;
>>> +
>>> +		attr_name_kobj->kset = tmp_set;
>>> +
>>> +		retval = kobject_init_and_add(attr_name_kobj,
>> &attr_name_ktype, NULL, "%s",
>>> +
>> 	elements[ATTR_NAME].string.pointer);
>>> +		if (retval) {
>>> +			kobject_put(attr_name_kobj);
>>> +			goto err_attr_init;
>>> +		}
>>> +
>>> +		/* enumerate all of this attribute */
>>> +		switch (attr_type) {
>>> +		case ENUM:
>>> +			retval = populate_enum_data(elements, instance_id,
>> attr_name_kobj);
>>> +			break;
>>> +		case INT:
>>> +			retval = populate_int_data(elements, instance_id,
>> attr_name_kobj);
>>> +			break;
>>> +		case STR:
>>> +			retval = populate_str_data(elements, instance_id,
>> attr_name_kobj);
>>> +			break;
>>> +		case PO:
>>> +			retval = populate_po_data(elements, instance_id,
>> attr_name_kobj);
>>> +			break;
>>> +		default:
>>> +			break;
>>> +		}
>>
>> The show functions don't take the mutex and can be called as soon as
>> kobject_init_and_add() is called, so it would be better to first populate the
>> data for the current instance_id and only then call kobject_init_and_add()
>>
> 
> Populate functions called here for each type of attribute uses
> attribute_koject which helps in attribute group cleanup.

Good point, and we do allocate the data before creating the kobjects,
so if a user manages to hit the race (which almost certainly would have
to be done intentionally) then the read would just result in an empty
string (rather then say a null pointer dereference oops).

So lets just keep this as is.

Regards,

Hans


      reply	other threads:[~2020-10-09  7:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29  2:55 Divya Bharathi
2020-09-29 10:30 ` Hans de Goede
2020-09-30  0:23 ` mark gross
2020-09-30 21:02   ` Limonciello, Mario
2020-10-01  9:26     ` Hans de Goede
2020-10-01 19:04       ` mark gross
2020-10-01 19:02     ` mark gross
2020-10-01 18:20 ` Hans de Goede
2020-10-01 19:37   ` Limonciello, Mario
2020-10-09  7:46     ` Hans de Goede
2020-10-06  8:37   ` Bharathi, Divya
2020-10-09  7:56     ` Hans de Goede
2020-10-06  8:46   ` Bharathi, Divya
2020-10-09  7:58     ` Hans de Goede [this message]

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=a7cc8b62-c87a-2253-de7a-7b463589ee4c@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=Divya.Bharathi@Dell.com \
    --cc=Mario.Limonciello@dell.com \
    --cc=Prasanth.Ksr@dell.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=divya27392@gmail.com \
    --cc=dvhart@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /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®