mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Lee Jones <lee@kernel.org>, Vojtech Pavlik <vojtech@ucw.cz>,
	Guanglei Zhu <zhugl3@xiaopeng.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 8/8] Input: adi - clean up formatting
Date: Sun, 29 Nov 2026 21:42:45 -0800	[thread overview]
Message-ID: <20261130054245.2215181-9-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20261130054245.2215181-1-dmitry.torokhov@gmail.com>

Wrap the static capability and hat-mapping tables within 80 columns,
add missing blank lines between declarations, move assignments out of
conditionals, split single-line statements and chained assignments onto
separate lines, balance braces and remove redundant void return
statements, and fix switch, conditional, and error-label indentation.

No functional changes intended.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/joystick/adi.c | 129 ++++++++++++++++++++++++-----------
 1 file changed, 90 insertions(+), 39 deletions(-)

diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 787af165db2a..9d461734a3d1 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -61,16 +61,46 @@ MODULE_LICENSE("GPL");
  * Names, buttons, axes ...
  */
 
-static const unsigned char adi_wmgpe_abs[] =	{ ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y };
-static const unsigned char adi_wmi_abs[] =	{ ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
-static const unsigned char adi_wmed3d_abs[] =	{ ABS_X, ABS_Y, ABS_THROTTLE, ABS_RZ, ABS_HAT0X, ABS_HAT0Y };
-static const unsigned char adi_cm2_abs[] =	{ ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
-static const unsigned char adi_wmf_abs[] =	{ ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
+static const unsigned char adi_wmgpe_abs[] = {
+	ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y
+};
+
+static const unsigned char adi_wmi_abs[] = {
+	ABS_X, ABS_Y, ABS_THROTTLE,
+	ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y
+};
+
+static const unsigned char adi_wmed3d_abs[] = {
+	ABS_X, ABS_Y, ABS_THROTTLE, ABS_RZ, ABS_HAT0X, ABS_HAT0Y
+};
+
+static const unsigned char adi_cm2_abs[] = {
+	ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ
+};
 
-static const unsigned short adi_wmgpe_key[] =	{ BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,  BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT };
-static const unsigned short adi_wmi_key[] =	{ BTN_TRIGGER,  BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA };
-static const unsigned short adi_wmed3d_key[] =	{ BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
-static const unsigned short adi_cm2_key[] =	{ BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
+static const unsigned char adi_wmf_abs[] = {
+	ABS_WHEEL, ABS_GAS, ABS_BRAKE,
+	ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y
+};
+
+static const unsigned short adi_wmgpe_key[] = {
+	BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,
+	BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT
+};
+
+static const unsigned short adi_wmi_key[] = {
+	BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2,
+	BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA
+};
+
+static const unsigned short adi_wmed3d_key[] = {
+	BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2,
+	BTN_BASE, BTN_BASE2
+};
+
+static const unsigned short adi_cm2_key[] = {
+	BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8
+};
 
 struct adi_model {
 	const char *name;
@@ -109,7 +139,10 @@ static const struct adi_model adi_models[] = {
 static struct {
 	int x;
 	int y;
-} adi_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}};
+} adi_hat_to_axis[] = {
+	{ 0, 0 }, { 0, -1 }, { 1, -1 }, { 1, 0 }, { 1, 1 },
+	{ 0, 1 }, { -1, 1 }, { -1, 0 }, { -1, -1 }
+};
 
 /*
  * Per-port information.
@@ -178,14 +211,16 @@ static void adi_read_packet(struct adi_port *port)
 				    adi[i].ret < ADI_MAX_LENGTH - 1 && t[i] > 0) {
 					adi[i].data[++adi[i].ret] = w;
 					t[i] = gameport_time(gameport, ADI_MAX_STROBE);
-				} else t[i] = 0;
-			} else if (!(x & ADI_STROBE_MASK)) s[i] = 1;
+				} else {
+					t[i] = 0;
+				}
+			} else if (!(x & ADI_STROBE_MASK)) {
+				s[i] = 1;
+			}
 		}
 	} while (t[0] > 0 || t[1] > 0);
 
 	local_irq_restore(flags);
-
-	return;
 }
 
 /*
@@ -195,13 +230,16 @@ static void adi_read_packet(struct adi_port *port)
 
 static void adi_move_bits(struct adi_port *port, int length)
 {
-	int i, offset;
 	struct adi *adi = port->adi;
+	int i, offset;
 
-	adi[0].idx = adi[1].idx = 0;
+	adi[0].idx = 0;
+	adi[1].idx = 0;
 
-	if (adi[0].ret <= 0 || adi[1].ret <= 0) return;
-	if (adi[0].data[0] & ADI_DATA_BIT || !(adi[1].data[0] & ADI_DATA_BIT)) return;
+	if (adi[0].ret <= 0 || adi[1].ret <= 0)
+		return;
+	if (adi[0].data[0] & ADI_DATA_BIT || !(adi[1].data[0] & ADI_DATA_BIT))
+		return;
 
 	if (length <= 0)
 		goto err_out;
@@ -231,7 +269,11 @@ static inline int adi_get_bits(struct adi *adi, int count)
 {
 	int bits = 0;
 	int i;
-	if ((adi->idx += count) > adi->ret) return 0;
+
+	adi->idx += count;
+	if (adi->idx > adi->ret)
+		return 0;
+
 	for (i = 0; i < count; i++)
 		bits |= !!(adi->data[adi->idx - i] & ADI_DATA_BIT) << i;
 	return bits;
@@ -248,7 +290,8 @@ static int adi_decode(struct adi *adi)
 	const unsigned short *key = adi->model->key;
 	int i, t;
 
-	if (adi->ret < adi->length || adi->id != (adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4)))
+	if (adi->ret < adi->length ||
+	    adi->id != (adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4)))
 		return -1;
 
 	for (i = 0; i < adi->axes10; i++)
@@ -267,7 +310,9 @@ static int adi_decode(struct adi *adi)
 	}
 
 	for (i = 0; i < adi->hats; i++) {
-		if ((t = adi_get_bits(adi, 4)) > 8) t = 0;
+		t = adi_get_bits(adi, 4);
+		if (t > 8)
+			t = 0;
 		input_report_abs(dev, *abs++, adi_hat_to_axis[t].x);
 		input_report_abs(dev, *abs++, adi_hat_to_axis[t].y);
 	}
@@ -294,7 +339,7 @@ static int adi_read(struct adi_port *port)
 
 	for (i = 0; i < 2; i++)
 		if (port->adi[i].length)
-			 result |= adi_decode(port->adi + i);
+			result |= adi_decode(port->adi + i);
 
 	return result;
 }
@@ -350,7 +395,7 @@ static void adi_init_digital(struct gameport *gameport)
 			msleep(seq[i]);
 		if (seq[i] < 0) {
 			mdelay(-seq[i]);
-			udelay(-seq[i]*14);	/* It looks like mdelay() is off by approx 1.4% */
+			udelay(-seq[i] * 14);	/* It looks like mdelay() is off by approx 1.4% */
 		}
 	}
 }
@@ -364,7 +409,8 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
 	if (adi->ret < ADI_MIN_ID_LENGTH) /* Minimum ID packet length */
 		return;
 
-	if (adi->ret < (t = adi_get_bits(adi, 10))) {
+	t = adi_get_bits(adi, 10);
+	if (adi->ret < t) {
 		dev_warn(dev, "Short ID packet: reported: %d != read: %d\n",
 			 t, adi->ret);
 		return;
@@ -372,7 +418,9 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
 
 	adi->id = adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4);
 
-	if ((t = adi_get_bits(adi, 4)) & ADI_FLAG_HAT) adi->hats++;
+	t = adi_get_bits(adi, 4);
+	if (t & ADI_FLAG_HAT)
+		adi->hats++;
 
 	adi->length = adi_get_bits(adi, 10);
 
@@ -422,15 +470,15 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
 	}
 
 	switch (adi->id) {
-		case ADI_ID_TPD:
-			adi->pad = 4;
-			break;
-		case ADI_ID_WGP:
-			adi->pad = 0;
-			break;
-		default:
-			adi->pad = -1;
-			break;
+	case ADI_ID_TPD:
+		adi->pad = 4;
+		break;
+	case ADI_ID_WGP:
+		adi->pad = 0;
+		break;
+	default:
+		adi->pad = -1;
+		break;
 	}
 
 	if (adi->pad >= 0) {
@@ -461,9 +509,10 @@ static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
 	struct input_dev *input_dev;
 	int i;
 
-	adi->dev = input_dev = input_allocate_device();
+	input_dev = input_allocate_device();
 	if (!input_dev)
 		return -ENOMEM;
+	adi->dev = input_dev;
 
 	if (adi->model->name)
 		scnprintf(adi->name, sizeof(adi->name),
@@ -506,7 +555,6 @@ static void adi_init_center(struct adi *adi)
 		return;
 
 	for (i = 0; i < adi_num_axes(adi); i++) {
-
 		t = adi->model->abs[i];
 		x = input_abs_get_val(adi->dev, t);
 
@@ -585,16 +633,19 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 	return 0;
 
- fail3: while (--i >= 0) {
+fail3:
+	while (--i >= 0) {
 		if (port->adi[i].length > 0) {
 			input_unregister_device(port->adi[i].dev);
 			port->adi[i].dev = NULL;
 		}
 	}
- fail2:	for (i = 0; i < 2; i++)
+fail2:
+	for (i = 0; i < 2; i++)
 		input_free_device(port->adi[i].dev);
 	gameport_close(gameport);
- fail1:	gameport_set_drvdata(gameport, NULL);
+fail1:
+	gameport_set_drvdata(gameport, NULL);
 	kfree(port);
 	return err;
 }
-- 
2.56.1.839.g22a8290db9-goog


      parent reply	other threads:[~2026-11-30  5:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
2026-11-30  5:42 ` [PATCH 1/8] Input: adi - fix out-of-bounds write in adi_read_packet() Dmitry Torokhov
2026-11-30  5:42 ` [PATCH 2/8] Input: adi - bound two-stream packet merge in adi_move_bits() Dmitry Torokhov
2026-11-30  5:42 ` [PATCH 3/8] Input: adi - validate ID packet axis and button counts Dmitry Torokhov
2026-11-30  5:42 ` [PATCH 4/8] Input: adi - use explicit fixed-width types and const tables Dmitry Torokhov
2026-11-30  5:42 ` [PATCH 5/8] Input: adi - simplify device name formatting Dmitry Torokhov
2026-11-30  5:42 ` [PATCH 6/8] Input: adi - use dev_warn() in adi_id_decode() Dmitry Torokhov
2026-11-30  5:42 ` [PATCH 7/8] Input: adi - use BIT() and GENMASK() for bitmasks and bit checks Dmitry Torokhov
2026-11-30  5:42 ` Dmitry Torokhov [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=20261130054245.2215181-9-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@ucw.cz \
    --cc=zhugl3@xiaopeng.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®