Commit 8aa035a8 authored by Cristian Ciocaltea's avatar Cristian Ciocaltea Committed by Jiri Kosina
Browse files

HID: playstation: Switch to scoped_guard() in {dualsense|dualshock4}_output_worker()



Those functions were initially excepted from using the scoped_guard()
infrastructure as they contain too many long statements, while adding
yet another level of indentation seemed to lower readability without
bringing an immediate benefit.

However, consistency should be more important, hence do the switch and
get rid of the remaining explicit acquires & releases of the spinlocks.

Signed-off-by: default avatarCristian Ciocaltea <cristian.ciocaltea@collabora.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.com>
parent 3969f77f
Loading
Loading
Loading
Loading
+129 −127
Original line number Diff line number Diff line
@@ -1308,13 +1308,11 @@ static void dualsense_output_worker(struct work_struct *work)
	struct dualsense *ds = container_of(work, struct dualsense, output_worker);
	struct dualsense_output_report report;
	struct dualsense_output_report_common *common;
	unsigned long flags;

	dualsense_init_output_report(ds, &report, ds->output_report_dmabuf);
	common = report.common;

	spin_lock_irqsave(&ds->base.lock, flags);

	scoped_guard(spinlock_irqsave, &ds->base.lock) {
		if (ds->update_rumble) {
			/* Select classic rumble style haptics and enable it. */
			common->valid_flag0 |= DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT;
@@ -1337,7 +1335,8 @@ static void dualsense_output_worker(struct work_struct *work)
		}

		if (ds->update_player_leds) {
		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE;
			common->valid_flag1 |=
				DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE;
			common->player_leds = ds->player_leds_state;

			ds->update_player_leds = false;
@@ -1366,17 +1365,21 @@ static void dualsense_output_worker(struct work_struct *work)
				} else {
					/* Mute HP and route R channel to SP */
					common->audio_control =
					FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS_OUTPUT_PATH_SEL, 0x3);
						FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS_OUTPUT_PATH_SEL,
							   0x3);
					/*
					 * Set SP hardware volume to 100%.
					 * Note the accepted range seems to be [0x3d..0x64]
					 */
				common->valid_flag0 |= DS_OUTPUT_VALID_FLAG0_SPEAKER_VOLUME_ENABLE;
					common->valid_flag0 |=
						DS_OUTPUT_VALID_FLAG0_SPEAKER_VOLUME_ENABLE;
					common->speaker_volume = 0x64;
					/* Set SP preamp gain to +6dB */
				common->valid_flag1 = DS_OUTPUT_VALID_FLAG1_AUDIO_CONTROL2_ENABLE;
					common->valid_flag1 =
						DS_OUTPUT_VALID_FLAG1_AUDIO_CONTROL2_ENABLE;
					common->audio_control2 =
					FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS2_SP_PREAMP_GAIN, 0x2);
						FIELD_PREP(DS_OUTPUT_AUDIO_FLAGS2_SP_PREAMP_GAIN,
							   0x2);
				}

				input_report_switch(ds->jack, SW_HEADPHONE_INSERT, val);
@@ -1396,18 +1399,20 @@ static void dualsense_output_worker(struct work_struct *work)

			if (ds->mic_muted) {
				/* Disable microphone */
			common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
				common->valid_flag1 |=
					DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
				common->power_save_control |= DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE;
			} else {
				/* Enable microphone */
			common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
			common->power_save_control &= ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE;
				common->valid_flag1 |=
					DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE;
				common->power_save_control &=
					~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE;
			}

			ds->update_mic_mute = false;
		}

	spin_unlock_irqrestore(&ds->base.lock, flags);
	}

	dualsense_send_output_report(ds, &report);
}
@@ -2264,13 +2269,11 @@ static void dualshock4_output_worker(struct work_struct *work)
	struct dualshock4 *ds4 = container_of(work, struct dualshock4, output_worker);
	struct dualshock4_output_report report;
	struct dualshock4_output_report_common *common;
	unsigned long flags;

	dualshock4_init_output_report(ds4, &report, ds4->output_report_dmabuf);
	common = report.common;

	spin_lock_irqsave(&ds4->base.lock, flags);

	scoped_guard(spinlock_irqsave, &ds4->base.lock) {
		/*
		 * Some 3rd party gamepads expect updates to rumble and lightbar
		 * together, and setting one may cancel the other.
@@ -2317,8 +2320,7 @@ static void dualshock4_output_worker(struct work_struct *work)
			common->lightbar_blink_off = ds4->lightbar_blink_off;
			ds4->update_lightbar_blink = false;
		}

	spin_unlock_irqrestore(&ds4->base.lock, flags);
	}

	/* Bluetooth packets need additional flags as well as a CRC in the last 4 bytes. */
	if (report.bt) {