lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240922111701.85965-1-didi1364@gmail.com>
Date: Sun, 22 Sep 2024 14:47:01 +0330
From: amin-amani <didi1364@...il.com>
To: johan@...nel.org
Cc: gregkh@...uxfoundation.org,
	linux-usb@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	"A.Amani" <didi1364@...il.com>
Subject: [PATCH] usb: serial: digi_acceleport: Improve readability and enhance error handling

From: "A.Amani" <didi1364@...il.com>

- Improved coding style to adhere to kernel standards as suggested by
  checkpatch.pl.
- Indented case statements for baud rate and word size to improve code
  readability.
- Separated null checks for port, serial, and private data for clearer
  error handling.
- Improved error messages to better indicate which specific data (port,
  serial, or private) is null.
- No functional changes, only structural improvements and clearer
  debugging output.

Signed-off-by: A.Amani <didi1364@...il.com>
---
 drivers/usb/serial/digi_acceleport.c | 105 +++++++++++++++++++--------
 1 file changed, 73 insertions(+), 32 deletions(-)

diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index d1dea3850576..da707967a0c4 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -685,25 +685,44 @@ static void digi_set_termios(struct tty_struct *tty,
 		}
 		switch (baud) {
 		/* drop DTR and RTS on transition to B0 */
-		case 0: digi_set_modem_signals(port, 0, 1); break;
-		case 50: arg = DIGI_BAUD_50; break;
-		case 75: arg = DIGI_BAUD_75; break;
-		case 110: arg = DIGI_BAUD_110; break;
-		case 150: arg = DIGI_BAUD_150; break;
-		case 200: arg = DIGI_BAUD_200; break;
-		case 300: arg = DIGI_BAUD_300; break;
-		case 600: arg = DIGI_BAUD_600; break;
-		case 1200: arg = DIGI_BAUD_1200; break;
-		case 1800: arg = DIGI_BAUD_1800; break;
-		case 2400: arg = DIGI_BAUD_2400; break;
-		case 4800: arg = DIGI_BAUD_4800; break;
-		case 9600: arg = DIGI_BAUD_9600; break;
-		case 19200: arg = DIGI_BAUD_19200; break;
-		case 38400: arg = DIGI_BAUD_38400; break;
-		case 57600: arg = DIGI_BAUD_57600; break;
-		case 115200: arg = DIGI_BAUD_115200; break;
-		case 230400: arg = DIGI_BAUD_230400; break;
-		case 460800: arg = DIGI_BAUD_460800; break;
+		case 0:
+			digi_set_modem_signals(port, 0, 1); break;
+		case 50:
+			arg = DIGI_BAUD_50; break;
+		case 75:
+			arg = DIGI_BAUD_75; break;
+		case 110:
+			arg = DIGI_BAUD_110; break;
+		case 150:
+			arg = DIGI_BAUD_150; break;
+		case 200:
+			arg = DIGI_BAUD_200; break;
+		case 300:
+			arg = DIGI_BAUD_300; break;
+		case 600:
+			arg = DIGI_BAUD_600; break;
+		case 1200:
+			arg = DIGI_BAUD_1200; break;
+		case 1800:
+			arg = DIGI_BAUD_1800; break;
+		case 2400:
+			arg = DIGI_BAUD_2400; break;
+		case 4800:
+			arg = DIGI_BAUD_4800; break;
+		case 9600:
+			arg = DIGI_BAUD_9600; break;
+		case 19200:
+			arg = DIGI_BAUD_19200; break;
+		case 38400:
+			arg = DIGI_BAUD_38400; break;
+		case 57600:
+			arg = DIGI_BAUD_57600; break;
+		case 115200:
+			arg = DIGI_BAUD_115200; break;
+		case 230400:
+			arg = DIGI_BAUD_230400; break;
+		case 460800:
+			arg = DIGI_BAUD_460800; break;
 		default:
 			arg = DIGI_BAUD_9600;
 			baud = 9600;
@@ -737,10 +756,14 @@ static void digi_set_termios(struct tty_struct *tty,
 	if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
 		arg = -1;
 		switch (cflag & CSIZE) {
-		case CS5: arg = DIGI_WORD_SIZE_5; break;
-		case CS6: arg = DIGI_WORD_SIZE_6; break;
-		case CS7: arg = DIGI_WORD_SIZE_7; break;
-		case CS8: arg = DIGI_WORD_SIZE_8; break;
+		case CS5:
+			arg = DIGI_WORD_SIZE_5; break;
+		case CS6:
+			arg = DIGI_WORD_SIZE_6; break;
+		case CS7:
+			arg = DIGI_WORD_SIZE_7; break;
+		case CS8:
+			arg = DIGI_WORD_SIZE_8; break;
 		default:
 			dev_dbg(dev,
 				"digi_set_termios: can't handle word size %d\n",
@@ -967,16 +990,30 @@ static void digi_write_bulk_callback(struct urb *urb)
 	int status = urb->status;
 	bool wakeup;
 
-	/* port and serial sanity check */
-	if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
-		pr_err("%s: port or port->private is NULL, status=%d\n",
+	/* port sanity check */
+	if (port == NULL) {
+		pr_err("%s: port is NULL, status=%d\n",
+			__func__, status);
+		return;
+	}
+	/* serial sanity check */
+	priv = usb_get_serial_port_data(port);
+	if (priv == NULL) {
+		pr_err("%s: port->private is NULL, status=%d\n",
 			__func__, status);
 		return;
 	}
 	serial = port->serial;
-	if (serial == NULL || (serial_priv = usb_get_serial_data(serial)) == NULL) {
+	if (serial == NULL) {
 		dev_err(&port->dev,
-			"%s: serial or serial->private is NULL, status=%d\n",
+			"%s: serial  is NULL, status=%d\n",
+			__func__, status);
+		return;
+	}
+	serial_priv = usb_get_serial_data(serial);
+	if (serial_priv == NULL) {
+		dev_err(&port->dev,
+			"%s: serial->private is NULL, status=%d\n",
 			__func__, status);
 		return;
 	}
@@ -1309,13 +1346,17 @@ static void digi_read_bulk_callback(struct urb *urb)
 			__func__, status);
 		return;
 	}
-	if (port->serial == NULL ||
-		(serial_priv = usb_get_serial_data(port->serial)) == NULL) {
-		dev_err(&port->dev, "%s: serial is bad or serial->private "
+	if (port->serial == NULL) {
+		dev_err(&port->dev, "%s: serial is bad,"
+			" status=%d\n", __func__, status);
+		return;
+	}
+	serial_priv = usb_get_serial_data(port->serial);
+	if (serial_priv == NULL) {
+		dev_err(&port->dev, "%s:serial->private "
 			"is NULL, status=%d\n", __func__, status);
 		return;
 	}
-
 	/* do not resubmit urb if it has any status error */
 	if (status) {
 		dev_err(&port->dev,
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ