Re: [PATCH v9 10/17] platform/x86: dell-smbios-wmi: Add new WMI dispatcher driver
From: Pali RohÃr
Date: Tue Oct 17 2017 - 15:10:55 EST
On Tuesday 17 October 2017 13:21:54 Mario Limonciello wrote:
> +static LIST_HEAD(wmi_list);
> +
> +static inline struct wmi_smbios_priv *get_first_smbios_priv(void)
> +{
> + return list_first_entry_or_null(&wmi_list,
> + struct wmi_smbios_priv,
> + list);
> +}
...
> +int dell_smbios_wmi_call(struct calling_interface_buffer *buffer)
> +{
> + struct wmi_smbios_priv *priv;
> + size_t difference;
> + size_t size;
> + int ret;
> +
> + priv = get_first_smbios_priv();
Mutex needs to be acquired before calling this function. Otherwise there
is a race condition between removing element from the list returned by
this call and later usage of structure priv.
> + if (!priv)
> + return -ENODEV;
> +
> + size = sizeof(struct calling_interface_buffer);
> + difference = priv->req_buf_size - sizeof(u64) - size;
> +
> + mutex_lock(&call_mutex);
> + memset(&priv->buf->ext, 0, difference);
> + memcpy(&priv->buf->std, buffer, size);
> + ret = run_smbios_call(priv->wdev);
> + memcpy(buffer, &priv->buf->std, size);
> + mutex_unlock(&call_mutex);
> +
> + return ret;
> +}
--
Pali RohÃr
pali.rohar@xxxxxxxxx