libftdi Archives

Subject: Re: (1.0/src/ftdi.c/10/10)Use default vendor/product strings for EEPROM when user doesn't supply some

From: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx, Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 27 Jul 2011 18:20:20 +0200
Hi Uwe,

On Wednesday, 20. July 2011 11:12:55 Uwe Bonnes wrote:
> diff --git a/src/ftdi.c b/src/ftdi.c
> index 31d945a..b2d6988 100644
> --- a/src/ftdi.c
> +++ b/src/ftdi.c
> @@ -2316,6 +2316,21 @@ int ftdi_eeprom_initdefaults(struct ftdi_context
> *ftdi, char * manufacturer, if (eeprom->product)
>              strcpy(eeprom->product, product);
>      }
> +    else
> +    {
> +        eeprom->product = malloc(21);
> +        if (eeprom->product)
> +            switch(ftdi->type)
> +            {
> +            case TYPE_AM:    strcpy(eeprom->product, "AM"); break;
> +            case TYPE_BM:    strcpy(eeprom->product, "BM"); break;
> +            case TYPE_2232C: strcpy(eeprom->product, "Dual RS232");
> break; +            case TYPE_R:     strcpy(eeprom->product, "FT232R USB
> UART"); break; +            case TYPE_2232H: strcpy(eeprom->product,
> "Dual RS232-HS"); break; +            case TYPE_4232H:
> strcpy(eeprom->product, "FT4232H"); break; +            case
> TYPE_232H:  strcpy(eeprom->product, "Single-RS232-HS"); break;
> +            }
> +    }
>  
>      if (eeprom->serial)
>          free (eeprom->serial);

I've applied most of your patches, thanks!

This patch needs some work:
- Provide a "default:" switch statement.
  Otherwise we will have an uninitialized buffer
  in eeprom->product for future/forgotten device types.
- Don't hardcode the "21" if possible or explain
  why it was chosen

Cheers,
Thomas

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread