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-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 24 Jul 2015 08:48:11 +0200
From:	Petr Tesarik <ptesarik@...e.com>
To:	Johan Hovold <johan@...nel.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:	Petr Tesarik <ptesarik@...e.com>,
	linux-usb@...r.kernel.org (open list:USB SERIAL SUBSYSTEM),
	linux-kernel@...r.kernel.org (open list),
	Petr Tesarik <ptesarik@...e.cz>
Subject: [PATCH 4/4] cp210x: Expose the part number in sysfs

From: Petr Tesarik <ptesarik@...e.cz>

Make it possible to read the cp210x part number from userspace by making
it a sysfs attribute.

Signed-off-by: Petr Tesarik <ptesarik@...e.com>
---
 drivers/usb/serial/cp210x.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index dbfc722..66de350 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -871,11 +871,24 @@ static void cp210x_break_ctl(struct tty_struct *tty, int break_state)
 	cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
 }
 
+static ssize_t part_number_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct usb_serial *serial = usb_get_intfdata(intf);
+	struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
+
+	return sprintf(buf, "%i\n", spriv->bPartNumber);
+}
+
+static DEVICE_ATTR_RO(part_number);
+
 static int cp210x_startup(struct usb_serial *serial)
 {
 	struct usb_host_interface *cur_altsetting;
 	struct cp210x_serial_private *spriv;
 	unsigned int partnum;
+	int result;
 
 	spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
 	if (!spriv)
@@ -892,13 +905,19 @@ static int cp210x_startup(struct usb_serial *serial)
 			   &partnum, 1, USB_CTRL_GET_TIMEOUT);
 	spriv->bPartNumber = partnum & 0xFF;
 
-	return 0;
+	result = device_create_file(&serial->interface->dev,
+				    &dev_attr_part_number);
+	if (result)
+		kfree(spriv);
+
+	return result;
 }
 
 static void cp210x_release(struct usb_serial *serial)
 {
 	struct cp210x_serial_private *spriv;
 
+	device_remove_file(&serial->interface->dev, &dev_attr_part_number);
 	spriv = usb_get_serial_data(serial);
 	kfree(spriv);
 }
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ