On Thu, Jun 14, 2018 at 10:08:46PM +0200, Loic Poulain wrote:
> 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.
> 
> 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.

> +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);
> +}

> @@ -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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to