Re: [PATCH v1] ASoC: tas2783-sdw: Add basic BPT support
From: Andy Shevchenko
Date: Tue Nov 03 2026 - 12:52:35 EST
On Tue, Nov 03, 2026 at 09:38:53PM +0800, Baojun Xu wrote:
> Add for BPT supported.
...
> +enum {
> + SDW_MSG_FLAG_READ = 0,
> + SDW_MSG_FLAG_WRITE,
Is it going to HW? If not, drop duplicate assignment. Otherwise assign *all* of
the enum to make code robust against modifications.
> +};
...
> +static int tas2783_fw_download_bpt(struct tas2783_prv *tas_dev,
> + const struct firmware *fmw)
> +{
> + struct sdw_slave *slave = tas_dev->sdw_peripheral;
> + struct sdw_bpt_section *sections = NULL;
> + struct sdw_bus *bus = slave->bus;
> + struct sdw_bpt_msg msg = {0};
'0' is not required.
> + struct tas_fw_file file;
> + struct tas_fw_hdr hdr;
> + size_t offset = FW_DL_OFFSET;
> + size_t img_sz = fmw->size;
> + const u8 *buf = fmw->data;
> + int num_sections = 0;
> + int i, ret;
> +
> + if (img_sz < FW_DL_OFFSET)
> + return -EINVAL;
> +
> + tas_fw_read_hdr(buf, &hdr);
> + if (hdr.size != img_sz)
> + return -EINVAL;
> +
> + while (offset < (img_sz - FW_FL_HDR)) {
> + size_t adv = (size_t)tas_fw_get_next_file(&buf[offset], &file);
> +
> + /*
> + * Reject a section whose payload runs past the image. Compare
> + * file.length (not adv) against the space left after this
> + * section's header, so the check is immune to the size_t wrap
> + * in tas_fw_get_next_file() on 32-bit kernels.
> + */
> + if (file.length > img_sz - offset - FW_FL_HDR) {
> + dev_err(tas_dev->dev,
> + "Firmware section at offset %zu exceeded.\n",
> + offset);
> + return -EINVAL;
> + }
> + if (num_sections >= TAS2783_MAX_FW_SECTIONS) {
> + dev_err(tas_dev->dev,
> + "BPT fw has too many sections (max %d)\n",
> + TAS2783_MAX_FW_SECTIONS);
> + return -EINVAL;
> + }
> + offset += adv;
> + num_sections++;
> + }
> +
> + if (num_sections == 0)
> + return -EINVAL;
> +
> + sections = kcalloc(num_sections, sizeof(*sections), GFP_KERNEL);
__free() ?
> + if (!sections)
> + return -ENOMEM;
> +
> + offset = FW_DL_OFFSET;
> + for (i = 0; i < num_sections && offset < (img_sz - FW_FL_HDR); i++) {
for (int i = 0; i < num_sections && offset < (img_sz - FW_FL_HDR); i++) {
> + size_t adv = (size_t)tas_fw_get_next_file(&buf[offset], &file);
> +
> + sections[i].addr = file.dest_addr;
> + sections[i].len = file.length;
> + sections[i].buf = file.fw_data;
> + offset += adv;
> +
> + dev_dbg(tas_dev->dev, "BPT section %d: addr=0x%x len=%d",
> + i, file.dest_addr, file.length);
> + }
> +
> + msg.sec = sections;
> + msg.sections = num_sections;
> + msg.dev_num = slave->dev_num;
> + msg.flags = SDW_MSG_FLAG_WRITE;
> +
> + dev_dbg(tas_dev->dev, "BPT starting: %d sections, dev_num=%d",
> + num_sections, slave->dev_num);
> +
> + ret = sdw_bpt_send_sync(bus, slave, &msg);
> +
Drop blank line.
> + if (ret < 0)
> + dev_err(tas_dev->dev, "BPT firmware download failed: %d", ret);
> + else
> + dev_dbg(tas_dev->dev,
> + "BPT firmware download complete: %d sections",
> + num_sections);
> +
> + kfree(sections);
> + return ret;
> +}
...
> static s32 tas_io_init(struct device *dev, struct sdw_slave *slave)
> {
> struct tas2783_prv *tas_dev = dev_get_drvdata(dev);
> + uint val;
What is this? Use unsigned int or u32 or other better fit.
> s32 ret;
>
> if (tas_dev->hw_init)
> return 0;
--
With Best Regards,
Andy Shevchenko