Skip to contentSkip to conversation

USB: serial: ftdi_sio: Add MTP NVM support

DISCUSSION Johan Hovold 1 participant 1 message Jun 18, 2018 USB

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines · Loic Poulain

Most of FTDI's devices have an EEPROM which records FTDI devices configuration setting (e.g. the VID, PID, I/O config...) and user data. FT230R chip integrates a 128-byte eeprom, FT230X a 2048-byte eeprom...

This patch adds support for FTDI EEPROM read/write via USB control transfers and register a new nvm device to the nvmem core.

Quoted 7 lines

This permits to expose the eeprom as a sysfs file, allowing userspace to read/modify FTDI configuration and its user data without having to rely on a specific userspace USB driver.

Moreover, any upcoming new tentative to add CBUS GPIO support could integrate CBUS EEPROM configuration reading in order to determine which of the CBUS pins are available as GPIO.

I'm not necessarily against the idea, but nvmem core needs to be fixed so that it can handle hotplugging before this can be considered for merging.

Right now it just returns -EBUSY from nvmem_unregister(), which results in all kinds of memory leaks, use-after-frees and crashes when user space holds the character device open while the device is being unplugged.

Quoted 9 lines
(quoted diff) +7 -0
+static void unregister_eeprom(struct usb_serial_port *port)
+{
+	struct ftdi_private *priv = usb_get_serial_port_data(port);
+
+	if (priv->eeprom)
+		nvmem_unregister(priv->eeprom);
+}

Review static int ftdi_sio_port_remove(struct usb_serial_port *port) · line 2044

Quoted 9 lines
(quoted diff) +3 -0
@@ -1931,6 +2036,9 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
 
+#if IS_ENABLED(CONFIG_USB_SERIAL_FTDI_SIO_NVMEM)
+	unregister_eeprom(port);
+#endif
 	remove_sysfs_attrs(port);
 
 	kfree(priv);

Thanks,
Johan
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html