[flashrom] [PATCH] Convert SPI chips to partial write

Michael Karcher flashrom at mkarcher.dialup.fu-berlin.de
Tue Jul 13 17:02:26 CEST 2010


Am Sonntag, den 11.07.2010, 01:02 +0200 schrieb Carl-Daniel Hailfinger:
 
> -int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf)
> +static int round_up(int val, int granularity)
>  {
> -	int total_size = 1024 * flash->total_size;
> -	int i;
> +	int tmp;
>  
> +	/* Premature optimization? You decide. */
> +	if (!(granularity & (granularity - 1))) {
> +		/* Granularity is a power of two. */
> +		return (val + granularity - 1) & ~ (granularity - 1);
> +	}
> +	
> +	tmp = val % granularity;
> +	if (!tmp)
> +		return val;
> +	else
> +		return val - tmp + granularity;
> +}
I in fact *do* decide. But not about the premature optimization, but
about a premature generalization. Don't write a general round_up
function, but just write the power-of-two case.

If you use the bitwise round-up here:
Acked-by: Michael Karcher <flashrom at mkarcher.dialup.fu-berlin.de>

Regards,
  Michael Karcher





More information about the flashrom mailing list