Re: [PATCH v9 3/4] USB: io_ti: Add firmware image sanity checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 31, 2015 at 01:55:07AM -0500, Peter E. Berger wrote:
> From: "Peter E. Berger" <pberger@xxxxxxxxxxx>
 
> +static int check_fw_sanity(struct edgeport_serial *serial,
> +		const struct firmware *fw)
> +{
> +	u16 length_total;
> +	u8 checksum = 0;
> +	int pos;
> +	struct device *dev = &serial->serial->interface->dev;
> +	struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
> +
> +	if (fw->size < sizeof(struct edgeport_fw_hdr)) {
> +		dev_err(dev, "incomplete fw header\n");
> +		return -EINVAL;
> +	}
> +
> +	length_total = le16_to_cpu(fw_hdr->length) +
> +			sizeof(struct edgeport_fw_hdr);
> +
> +	if (fw->size != length_total) {
> +		dev_err(dev, "bad fw size (expected: %u, got: %zu)\n",
> +				length_total, fw->size);
> +		return -EINVAL;
> +	}
> +
> +	for (pos = sizeof(struct edgeport_fw_hdr); pos < fw->size; ++pos)
> +		checksum = (checksum + fw->data[pos]) & 0xFF;

I simplified this to

		checksum += fw->data[pos];

before applying.

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



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux