public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: Amireddy mallikarjuna reddy <mallikarjuna.reddy@ftdichip.com>,
	arun.pappan@ftdichip.com, sowjanya.reddy@ftdichip.com,
	malliamireddy009@gmail.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 08/12] USB: serial: ftdi_sio: clean up attribute handling
Date: Sun, 11 Sep 2022 16:02:12 +0200	[thread overview]
Message-ID: <20220911140216.30481-9-johan@kernel.org> (raw)
In-Reply-To: <20220911140216.30481-1-johan@kernel.org>

The driver exposes two attributes for all chip types but FT232A, which
doesn't have a configurable latency timer, and SIO, which (probably)
doesn't support the event-char mechanism either.

Explicitly test for the exceptions rather than list each and every
supported device type in the attribute helpers.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/ftdi_sio.c | 47 ++++++++++++-----------------------
 1 file changed, 16 insertions(+), 31 deletions(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 58e0acb211df..835e12fc971a 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1726,46 +1726,31 @@ static DEVICE_ATTR_WO(event_char);
 static int create_sysfs_attrs(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
-	int retval = 0;
-
-	/* XXX I've no idea if the original SIO supports the event_char
-	 * sysfs parameter, so I'm playing it safe.  */
-	if (priv->chip_type != SIO) {
-		dev_dbg(&port->dev, "sysfs attributes for %s\n", ftdi_chip_name[priv->chip_type]);
-		retval = device_create_file(&port->dev, &dev_attr_event_char);
-		if ((!retval) &&
-		    (priv->chip_type == FT232B ||
-		     priv->chip_type == FT2232C ||
-		     priv->chip_type == FT232R ||
-		     priv->chip_type == FT2232H ||
-		     priv->chip_type == FT4232H ||
-		     priv->chip_type == FT232H ||
-		     priv->chip_type == FTX)) {
-			retval = device_create_file(&port->dev,
-						    &dev_attr_latency_timer);
-		}
+	enum ftdi_chip_type type = priv->chip_type;
+	int ret = 0;
+
+	if (type != SIO) {
+		ret = device_create_file(&port->dev, &dev_attr_event_char);
+		if (ret)
+			return ret;
 	}
-	return retval;
+
+	if (type != SIO && type != FT232A)
+		ret = device_create_file(&port->dev, &dev_attr_latency_timer);
+
+	return ret;
 }
 
 static void remove_sysfs_attrs(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
+	enum ftdi_chip_type type = priv->chip_type;
 
-	/* XXX see create_sysfs_attrs */
-	if (priv->chip_type != SIO) {
+	if (type != SIO)
 		device_remove_file(&port->dev, &dev_attr_event_char);
-		if (priv->chip_type == FT232B ||
-		    priv->chip_type == FT2232C ||
-		    priv->chip_type == FT232R ||
-		    priv->chip_type == FT2232H ||
-		    priv->chip_type == FT4232H ||
-		    priv->chip_type == FT232H ||
-		    priv->chip_type == FTX) {
-			device_remove_file(&port->dev, &dev_attr_latency_timer);
-		}
-	}
 
+	if (type != SIO && type != FT232A)
+		device_remove_file(&port->dev, &dev_attr_latency_timer);
 }
 
 #ifdef CONFIG_GPIOLIB
-- 
2.35.1


  parent reply	other threads:[~2022-09-11 14:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-11 14:02 [PATCH 00/12] USB: serial: ftdi_sio: type cleanup and HP/HA support Johan Hovold
2022-09-11 14:02 ` [PATCH 01/12] USB: serial: ftdi_sio: clean up chip type enum Johan Hovold
2022-09-11 14:02 ` [PATCH 02/12] USB: serial: ftdi_sio: drop redundant chip type comments Johan Hovold
2022-09-11 14:02 ` [PATCH 03/12] USB: serial: ftdi_sio: rename chip types Johan Hovold
2022-09-11 14:02 ` [PATCH 04/12] USB: serial: ftdi_sio: include FT2232D in type string Johan Hovold
2022-09-11 14:02 ` [PATCH 05/12] USB: serial: ftdi_sio: rename channel index Johan Hovold
2022-09-11 14:02 ` [PATCH 06/12] USB: serial: ftdi_sio: tighten device-type detection Johan Hovold
2022-09-11 14:02 ` [PATCH 07/12] USB: serial: ftdi_sio: clean up modem-status handling Johan Hovold
2022-09-11 14:02 ` Johan Hovold [this message]
2022-09-11 14:02 ` [PATCH 09/12] USB: serial: ftdi_sio: clean up baudrate request Johan Hovold
2022-09-11 14:02 ` [PATCH 10/12] USB: serial: ftdi_sio: assume hi-speed type Johan Hovold
2022-09-11 14:02 ` [PATCH 11/12] USB: serial: ftdi_sio: simplify divisor handling Johan Hovold
2022-09-11 14:02 ` [PATCH 12/12] USB: serial: ftdi_sio: add support for HP and HA devices Johan Hovold

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=20220911140216.30481-9-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=arun.pappan@ftdichip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=malliamireddy009@gmail.com \
    --cc=mallikarjuna.reddy@ftdichip.com \
    --cc=sowjanya.reddy@ftdichip.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