All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Shenghao Ding <shenghao-ding@ti.com>
Cc: broonie@kernel.org, tiwai@suse.de, 13916275206@139.com,
	13564923607@139.com, alsa-devel@alsa-project.org,
	baojun.xu@ti.com
Subject: Re: [PATCH v3] ASoC: tas2781: Support dsp firmware Alpha and Beta seaies
Date: Tue, 25 Feb 2025 16:40:36 +0200	[thread overview]
Message-ID: <Z73WZLrBrtVc69dn@smile.fi.intel.com> (raw)
In-Reply-To: <20250225140316.1049-1-shenghao-ding@ti.com>

On Tue, Feb 25, 2025 at 10:03:16PM +0800, Shenghao Ding wrote:
> For calibration, basic version does not contain any calibration addresses,
> it depends on calibration tool to convery the addresses to the driver.
> Since Alpha and Beta firmware, all the calibration addresses are saved
> into the firmware.

...

> +static void hex_parse_u8(unsigned char *item, const unsigned char *val,
> +	int len)
> +{
> +	for (int i = 0; i < len; i++)
> +		item[i] = val[i];

memcpy() ?

> +}

...

> +static void hex_parse_u24(unsigned int *item, const unsigned char *val)
> +{
> +	*item = TASDEVICE_REG(val[0], val[1], val[2]);
> +}

Also useless function, just use this  macro directly.

...

> +static void fct_param_address_parser(struct cali_reg *r,
> +	struct tasdevice_fw *tas_fmw)
> +{
> +	struct fct_param_address *p = &(tas_fmw->fct_par_addr);

Unneeded parentheses.

> +	int i;

unsigned int ?

> +
> +	for (i = 0; i < 20; i++) {
> +		const unsigned char *dat = &p->data[24 * i];

Okay, you have 24-byte records.

> +		if (dat[23] != 1)
> +			break;

> +		if (strstr(dat, "umg_SsmKEGCye") != NULL) {

These calls basically suggest that the data may be not at the same offset.
But at the same time they don't have boundary checks and there is a chance
that the tail of one of these string comparisons may trigger if the value
appears to be the same, like "Cye".

Instead, better to introduce a special data type or even data types, where
you put string with limited length and respective data, like u24/i8 in your
terminology. With that this code becomes much more clearer.

> +			hex_parse_u24(&r->pow_reg, &dat[20]);
> +			continue;
> +		}
> +		if (strstr(dat, "iks_E0") != NULL) {
> +			hex_parse_u24(&r->r0_reg, &dat[20]);
> +			continue;
> +		}
> +		if (strstr(dat, "yep_LsqM0") != NULL) {
> +			hex_parse_u24(&r->invr0_reg, &dat[20]);
> +			continue;
> +		}
> +		if (strstr(dat, "oyz_U0_ujx") != NULL) {
> +			hex_parse_u24(&r->r0_low_reg, &dat[20]);
> +			continue;
> +		}
> +		if (strstr(dat, "iks_GC_GMgq") != NULL) {
> +			hex_parse_u24(&r->tlimit_reg, &dat[20]);
> +			continue;
> +		}
> +		if (strstr(dat, "gou_Yao") != NULL) {
> +			hex_parse_u8(p->thr, &dat[20], 3);
> +			continue;
> +		}
> +		if (strstr(dat, "kgd_Wsc_Qsbp") != NULL) {
> +			hex_parse_u8(p->plt_flg, &dat[20], 3);
> +			continue;
> +		}
> +		if (strstr(dat, "yec_CqseSsqs") != NULL) {
> +			hex_parse_u8(p->sin_gn, &dat[20], 3);
> +			continue;
> +		}
> +		if (strstr(dat, "iks_SogkGgog2") != NULL) {
> +			hex_parse_u8(p->sin_gn2, &dat[20], 3);
> +			continue;
> +		}
> +		if (strstr(dat, "yec_Sae_Y") != NULL) {
> +			hex_parse_u8(p->thr2, &dat[20], 3);
> +			continue;
> +		}
> +		if (strstr(dat, "Re_Int") != NULL) {
> +			hex_parse_u8(p->r0_reg, &dat[20], 3);
> +			continue;
> +		}
> +		/* Check whether the spk connection is open */
> +		if (strstr(dat, "SigFlag") != NULL) {
> +			hex_parse_u8(p->tf_reg, &dat[20], 3);
> +			continue;
> +		}
> +		if (strstr(dat, "a1_Int") != NULL) {
> +			hex_parse_u8(p->a1_reg, &dat[20], 3);
> +			continue;
> +		}
> +		if (strstr(dat, "a2_Int") != NULL) {
> +			hex_parse_u8(p->a2_reg, &dat[20], 3);
> +			continue;
> +		}
> +	}
> +}

...

> +static int fw_parse_fct_param_address(struct tasdevice_priv *tas_priv,
> +	struct tasdevice_fw *tas_fmw, const struct firmware *fmw, int offset)
> +{
> +	struct fct_param_address *p = &(tas_fmw->fct_par_addr);
> +	struct calidata *cali_data = &tas_priv->cali_data;
> +	struct cali_reg *r = &cali_data->cali_reg_array;
> +	const unsigned char *data = fmw->data;
> +
> +	if (offset + 520 > fmw->size) {
> +		dev_err(tas_priv->dev, "%s: File Size error\n", __func__);

> +		offset = -1;
> +		goto out;

Just return directly and use proper error codes.

> +	}
> +
> +	/* skip reserved part */
> +	offset += 40;
> +	p->size = 480;
> +	p->data = kmemdup(&data[offset], 480, GFP_KERNEL);
> +	if (!p->data) {

> +		offset = -1;
> +		goto out;

Ditto.

> +	}
> +	offset += 480;
> +	fct_param_address_parser(r, tas_fmw);

> +out:

Useless label.

> +	return offset;
> +}

...

>  	offset = tas_priv->fw_parse_configuration_data(tas_priv,
>  		tas_fmw, fmw, offset);
> -	if (offset < 0)
> +	if (offset < 0) {
>  		ret = offset;

This is the error code from offset, right? what you use is -1 in both cases
which maps currently to EPERM.

> +		goto out;
> +	}

...

> +	if (tas_priv->fw_parse_fct_param_address) {
> +		offset = tas_priv->fw_parse_fct_param_address(tas_priv,
> +			tas_fmw, fmw, offset);
> +		if (offset < 0)
> +			ret = offset;

Ditto.

> +	}

...

>  out:

Yet another useless label.

>  	return ret;

...

> +		if (tas_priv->dspbin_typ == TASDEV_ALPHA)
> +			tasdevice_dev_bulk_write(tas_priv, i, t->reg,
> +				t->val, 4);

Follow the logical splits

			tasdevice_dev_bulk_write(tas_priv, i,
						 t->reg, t->val, 4);

or do it on a single line (it's only 81 characters).

			tasdevice_dev_bulk_write(tas_priv, i, t->reg, t->val, 4);

...

> +		if (tas_priv->dspbin_typ)
> +			reg = TASDEVICE_REG(p->tf_reg[0], p->tf_reg[1],
> +				p->tf_reg[2]);

One line will be not so big (86 characters).

...

> +static void cali_reg_update(struct bulk_reg_val *p,
> +	struct fct_param_address *t)
> +{
> +	const int sum = ARRAY_SIZE(tas2781_cali_start_reg);
> +	int reg = 0;
> +	int j;
> +
> +	for (j = 0; j < sum; j++) {
> +		switch (tas2781_cali_start_reg[j].reg) {
> +		case 0:
> +		reg = TASDEVICE_REG(t->thr[0], t->thr[1], t->thr[2]);

Indentation issues with all these reg = ...

> +			break;
> +		case TAS2781_PRM_PLT_FLAG_REG:

> +		reg = TASDEVICE_REG(t->plt_flg[0], t->plt_flg[1],
> +			t->plt_flg[2]);

You have room on the previous line.

> +			break;
> +		case TAS2781_PRM_SINEGAIN_REG:
> +		reg = TASDEVICE_REG(t->sin_gn[0], t->sin_gn[1], t->sin_gn[2]);
> +			break;
> +		case TAS2781_PRM_SINEGAIN2_REG:
> +		reg = TASDEVICE_REG(t->sin_gn[0], t->sin_gn[1], t->sin_gn[2]);
> +			break;
> +		default:
> +		reg = 0;
> +			break;
> +		}
> +		if (reg)
> +			p[j].reg = reg;
> +	}
> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-02-25 14:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25 14:03 [PATCH v3] ASoC: tas2781: Support dsp firmware Alpha and Beta seaies Shenghao Ding
2025-02-25 14:40 ` Andy Shevchenko [this message]
2025-02-27 11:58   ` [EXTERNAL] " Ding, Shenghao
2025-02-27 15:09     ` Andy Shevchenko
2025-02-27 15:12       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z73WZLrBrtVc69dn@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=13564923607@139.com \
    --cc=13916275206@139.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=baojun.xu@ti.com \
    --cc=broonie@kernel.org \
    --cc=shenghao-ding@ti.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.