mirror of https://github.com/torvalds/linux.git
hwmon: (asus_rog_ryujin) Rely on subsystem locking
Attribute access is now serialized in the hardware monitoring core, so locking in the driver code is no longer necessary. Drop it. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
75616264e0
commit
b4306c0c8e
|
|
@ -81,10 +81,6 @@ static const char *const rog_ryujin_speed_label[] = {
|
||||||
struct rog_ryujin_data {
|
struct rog_ryujin_data {
|
||||||
struct hid_device *hdev;
|
struct hid_device *hdev;
|
||||||
struct device *hwmon_dev;
|
struct device *hwmon_dev;
|
||||||
/* For locking access to buffer */
|
|
||||||
struct mutex buffer_lock;
|
|
||||||
/* For queueing multiple readers */
|
|
||||||
struct mutex status_report_request_mutex;
|
|
||||||
/* For reinitializing the completions below */
|
/* For reinitializing the completions below */
|
||||||
spinlock_t status_report_request_lock;
|
spinlock_t status_report_request_lock;
|
||||||
struct completion cooler_status_received;
|
struct completion cooler_status_received;
|
||||||
|
|
@ -153,18 +149,10 @@ static umode_t rog_ryujin_is_visible(const void *data,
|
||||||
/* Writes the command to the device with the rest of the report filled with zeroes */
|
/* Writes the command to the device with the rest of the report filled with zeroes */
|
||||||
static int rog_ryujin_write_expanded(struct rog_ryujin_data *priv, const u8 *cmd, int cmd_length)
|
static int rog_ryujin_write_expanded(struct rog_ryujin_data *priv, const u8 *cmd, int cmd_length)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
|
|
||||||
mutex_lock(&priv->buffer_lock);
|
|
||||||
|
|
||||||
memcpy_and_pad(priv->buffer, MAX_REPORT_LENGTH, cmd, cmd_length, 0x00);
|
memcpy_and_pad(priv->buffer, MAX_REPORT_LENGTH, cmd, cmd_length, 0x00);
|
||||||
ret = hid_hw_output_report(priv->hdev, priv->buffer, MAX_REPORT_LENGTH);
|
return hid_hw_output_report(priv->hdev, priv->buffer, MAX_REPORT_LENGTH);
|
||||||
|
|
||||||
mutex_unlock(&priv->buffer_lock);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assumes priv->status_report_request_mutex is locked */
|
|
||||||
static int rog_ryujin_execute_cmd(struct rog_ryujin_data *priv, const u8 *cmd, int cmd_length,
|
static int rog_ryujin_execute_cmd(struct rog_ryujin_data *priv, const u8 *cmd, int cmd_length,
|
||||||
struct completion *status_completion)
|
struct completion *status_completion)
|
||||||
{
|
{
|
||||||
|
|
@ -196,14 +184,11 @@ static int rog_ryujin_execute_cmd(struct rog_ryujin_data *priv, const u8 *cmd, i
|
||||||
|
|
||||||
static int rog_ryujin_get_status(struct rog_ryujin_data *priv)
|
static int rog_ryujin_get_status(struct rog_ryujin_data *priv)
|
||||||
{
|
{
|
||||||
int ret = mutex_lock_interruptible(&priv->status_report_request_mutex);
|
int ret;
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!time_after(jiffies, priv->updated + msecs_to_jiffies(STATUS_VALIDITY))) {
|
if (!time_after(jiffies, priv->updated + msecs_to_jiffies(STATUS_VALIDITY))) {
|
||||||
/* Data is up to date */
|
/* Data is up to date */
|
||||||
goto unlock_and_return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve cooler status */
|
/* Retrieve cooler status */
|
||||||
|
|
@ -211,36 +196,30 @@ static int rog_ryujin_get_status(struct rog_ryujin_data *priv)
|
||||||
rog_ryujin_execute_cmd(priv, get_cooler_status_cmd, GET_CMD_LENGTH,
|
rog_ryujin_execute_cmd(priv, get_cooler_status_cmd, GET_CMD_LENGTH,
|
||||||
&priv->cooler_status_received);
|
&priv->cooler_status_received);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto unlock_and_return;
|
return ret;
|
||||||
|
|
||||||
/* Retrieve controller status (speeds) */
|
/* Retrieve controller status (speeds) */
|
||||||
ret =
|
ret =
|
||||||
rog_ryujin_execute_cmd(priv, get_controller_speed_cmd, GET_CMD_LENGTH,
|
rog_ryujin_execute_cmd(priv, get_controller_speed_cmd, GET_CMD_LENGTH,
|
||||||
&priv->controller_status_received);
|
&priv->controller_status_received);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto unlock_and_return;
|
return ret;
|
||||||
|
|
||||||
/* Retrieve cooler duty */
|
/* Retrieve cooler duty */
|
||||||
ret =
|
ret =
|
||||||
rog_ryujin_execute_cmd(priv, get_cooler_duty_cmd, GET_CMD_LENGTH,
|
rog_ryujin_execute_cmd(priv, get_cooler_duty_cmd, GET_CMD_LENGTH,
|
||||||
&priv->cooler_duty_received);
|
&priv->cooler_duty_received);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto unlock_and_return;
|
return ret;
|
||||||
|
|
||||||
/* Retrieve controller duty */
|
/* Retrieve controller duty */
|
||||||
ret =
|
ret =
|
||||||
rog_ryujin_execute_cmd(priv, get_controller_duty_cmd, GET_CMD_LENGTH,
|
rog_ryujin_execute_cmd(priv, get_controller_duty_cmd, GET_CMD_LENGTH,
|
||||||
&priv->controller_duty_received);
|
&priv->controller_duty_received);
|
||||||
if (ret < 0)
|
|
||||||
goto unlock_and_return;
|
|
||||||
|
|
||||||
priv->updated = jiffies;
|
|
||||||
|
|
||||||
unlock_and_return:
|
|
||||||
mutex_unlock(&priv->status_report_request_mutex);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
priv->updated = jiffies;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -303,14 +282,11 @@ static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channel
|
||||||
* Retrieve cooler duty since both pump and internal fan are set
|
* Retrieve cooler duty since both pump and internal fan are set
|
||||||
* together, then write back with one of them modified.
|
* together, then write back with one of them modified.
|
||||||
*/
|
*/
|
||||||
ret = mutex_lock_interruptible(&priv->status_report_request_mutex);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
ret =
|
ret =
|
||||||
rog_ryujin_execute_cmd(priv, get_cooler_duty_cmd, GET_CMD_LENGTH,
|
rog_ryujin_execute_cmd(priv, get_cooler_duty_cmd, GET_CMD_LENGTH,
|
||||||
&priv->cooler_duty_received);
|
&priv->cooler_duty_received);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto unlock_and_return;
|
return ret;
|
||||||
|
|
||||||
memcpy(set_cmd, set_cooler_duty_cmd, SET_CMD_LENGTH);
|
memcpy(set_cmd, set_cooler_duty_cmd, SET_CMD_LENGTH);
|
||||||
|
|
||||||
|
|
@ -329,11 +305,7 @@ static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channel
|
||||||
set_cmd[RYUJIN_SET_COOLER_FAN_DUTY_OFFSET] = val;
|
set_cmd[RYUJIN_SET_COOLER_FAN_DUTY_OFFSET] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = rog_ryujin_execute_cmd(priv, set_cmd, SET_CMD_LENGTH, &priv->cooler_duty_set);
|
return rog_ryujin_execute_cmd(priv, set_cmd, SET_CMD_LENGTH, &priv->cooler_duty_set);
|
||||||
unlock_and_return:
|
|
||||||
mutex_unlock(&priv->status_report_request_mutex);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Controller fan duty (channel == 2). No need to retrieve current
|
* Controller fan duty (channel == 2). No need to retrieve current
|
||||||
|
|
@ -538,8 +510,6 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_id
|
||||||
goto fail_and_close;
|
goto fail_and_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_init(&priv->status_report_request_mutex);
|
|
||||||
mutex_init(&priv->buffer_lock);
|
|
||||||
spin_lock_init(&priv->status_report_request_lock);
|
spin_lock_init(&priv->status_report_request_lock);
|
||||||
init_completion(&priv->cooler_status_received);
|
init_completion(&priv->cooler_status_received);
|
||||||
init_completion(&priv->controller_status_received);
|
init_completion(&priv->controller_status_received);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue