From: amin-amani <didi1364@gmail.com>
To: johan@kernel.org
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, "A.Amani" <didi1364@gmail.com>
Subject: [PATCH] usb: serial: digi_acceleport: Improve readability and enhance error handling
Date: Sun, 22 Sep 2024 14:47:01 +0330 [thread overview]
Message-ID: <20240922111701.85965-1-didi1364@gmail.com> (raw)
From: "A.Amani" <didi1364@gmail.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@gmail.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
next reply other threads:[~2024-09-22 11:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-22 11:17 amin-amani [this message]
2024-09-22 14:56 ` [PATCH] usb: serial: digi_acceleport: Improve readability and enhance error handling Greg KH
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=20240922111701.85965-1-didi1364@gmail.com \
--to=didi1364@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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