RE: [EXTERNAL] Re: [PATCH v1] ASoC: tas2781: fixed compiling issue in m68k

From: Ding, Shenghao
Date: Tue Oct 03 2023 - 06:47:40 EST




> -----Original Message-----
> From: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Sent: Tuesday, October 3, 2023 3:24 AM
> To: Ding, Shenghao <shenghao-ding@xxxxxx>
> Cc: broonie@xxxxxxxxxx; robh+dt@xxxxxxxxxx;
> andriy.shevchenko@xxxxxxxxxxxxxxx; lgirdwood@xxxxxxxxx; perex@xxxxxxxx;
> pierre-louis.bossart@xxxxxxxxxxxxxxx; Lu, Kevin <kevin-lu@xxxxxx>;
> 13916275206@xxxxxxx; alsa-devel@xxxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; liam.r.girdwood@xxxxxxxxx; mengdong.lin@xxxxxxxxx;
> Xu, Baojun <baojun.xu@xxxxxx>; thomas.gfeller@xxxxxxxxxx; Gupta, Peeyush
> <peeyush@xxxxxx>; Navada Kanyana, Mukund <navada@xxxxxx>;
> tiwai@xxxxxxx
> Subject: [EXTERNAL] Re: [PATCH v1] ASoC: tas2781: fixed compiling issue in
> m68k
>
> Hi Shenghao,
>
> Thanks for your patch!
>
> On Mon, Oct 2, 2023 at 4:38 PM Shenghao Ding <shenghao-ding@xxxxxx>
> wrote:
> > fixed m68k compiling issue: mapping table can save code field; storing
> > the
>
> Please replicate the actual error message from the compiler, so it is recorded in
> the commit description, and easy to find when someone searches for the actual
> error message
>
> From the Reported-by (which is not included in the actual description, as it is
> below the "---"):
>
> {standard input}: Assembler messages:
> >> {standard input}:992: Error: value -148 out of range
> {standard input}:992: Error: value of ffffff6c too large for field of 1 byte at
> 0000045f
>
> > dev_idx as a member of block can reduce unnecessary time and system
> > resource comsumption of dev_idx mapping every time the block data
> > writing to the dsp.
>
> I am sorry, but I don't understand what this means.
> Can you please elaborate?
>
> Also, can you please explain what the real issue is?
> (My first guess when seeing the error message before was that a signed
> integer is truncated to an unsigned char or so, but I couldn't see immediately
> where that is happening)
Sorry to late feedback. I had been troubled by this issue for several weeks. At first, I also think it would one of variables overflow, according to the compiling error message. However, after investigation, no result came out. In fact, compiler will report the line number where the variable overflow is, if there was risk on the variable overflow. Yet, this compiling error did not report any line number. Finally, I didn’t realize that it would be the code section overflow until that compiling error message magically disappeared, one day I removed some functions in the tas2781-fwlib.c. So, I began to simplify some functions in the code.
>
> > Signed-off-by: Shenghao Ding <shenghao-ding@xxxxxx>
> >
> > ---
> > Changes in v1:
> > - | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > | Closes:
> > | https://lore.kernel.org/oe-kbuild-all/202309222048.RnSqEIK5-lkp@intel.
> > | com/
>
> > --- a/include/sound/tas2781-dsp.h
> > +++ b/include/sound/tas2781-dsp.h
> > @@ -77,6 +77,11 @@ struct tasdev_blk {
> > unsigned int nr_cmds;
> > unsigned int blk_size;
> > unsigned int nr_subblocks;
> > + /* fixed m68k compiling issue, storing the dev_idx as a member of block
> > + * can reduce unnecessary timeand system resource comsumption of
> > + * dev_idx mapping every time the block data writing to the dsp.
> > + */
>
> What is so special about "m68k" that it (1) fails there (and only there?
> and only for some config/compiler combos, as it builds fine for me?), and (2) is
> needed to mention this in comments all over the place?
>
> > + unsigned char dev_idx;
> > unsigned char *data;
> > };
> >
> > diff --git a/sound/soc/codecs/tas2781-fmwlib.c
> > b/sound/soc/codecs/tas2781-fmwlib.c
> > index eb55abae0d7b..e27775d834e9 100644
> > --- a/sound/soc/codecs/tas2781-fmwlib.c
> > +++ b/sound/soc/codecs/tas2781-fmwlib.c
> > @@ -80,10 +80,72 @@ struct tas_crc {
> > unsigned char len;
> > };
> >
> > +struct blktyp_devidx_map {
> > + unsigned char blktyp;
> > + unsigned char dev_idx;
> > +};
> > +
> > static const char deviceNumber[TASDEVICE_DSP_TAS_MAX_DEVICE] = {
> > 1, 2, 1, 2, 1, 1, 0, 2, 4, 3, 1, 2, 3, 4 };
> >
> > +/* fixed m68k compiling issue: mapping table can save code field */
> > +static const struct blktyp_devidx_map ppc3_tas2781_mapping_table[] = {
> > + { MAIN_ALL_DEVICES_1X, 0x80 },
> > + { MAIN_DEVICE_A_1X, 0x81 },
> > + { COEFF_DEVICE_A_1X, 0xC1 },
> > + { PRE_DEVICE_A_1X, 0xC1 },
> > + { PRE_SOFTWARE_RESET_DEVICE_A, 0xC1 },
> > + { POST_SOFTWARE_RESET_DEVICE_A, 0xC1 },
> > + { MAIN_DEVICE_B_1X, 0x82 },
> > + { COEFF_DEVICE_B_1X, 0xC2 },
> > + { PRE_DEVICE_B_1X, 0xC2 },
> > + { PRE_SOFTWARE_RESET_DEVICE_B, 0xC2 },
> > + { POST_SOFTWARE_RESET_DEVICE_B, 0xC2 },
> > + { MAIN_DEVICE_C_1X, 0x83 },
> > + { COEFF_DEVICE_C_1X, 0xC3 },
> > + { PRE_DEVICE_C_1X, 0xC3 },
> > + { PRE_SOFTWARE_RESET_DEVICE_C, 0xC3 },
> > + { POST_SOFTWARE_RESET_DEVICE_C, 0xC3 },
> > + { MAIN_DEVICE_D_1X, 0x84 },
> > + { COEFF_DEVICE_D_1X, 0xC4 },
> > + { PRE_DEVICE_D_1X, 0xC4 },
> > + { PRE_SOFTWARE_RESET_DEVICE_D, 0xC4 },
> > + { POST_SOFTWARE_RESET_DEVICE_D, 0xC4 }, };
> > +
> > +static const struct blktyp_devidx_map ppc3_mapping_table[] = {
> > + { MAIN_ALL_DEVICES_1X, 0x80 },
> > + { MAIN_DEVICE_A_1X, 0x81 },
> > + { COEFF_DEVICE_A_1X, 0xC1 },
> > + { PRE_DEVICE_A_1X, 0xC1 },
> > + { MAIN_DEVICE_B_1X, 0x82 },
> > + { COEFF_DEVICE_B_1X, 0xC2 },
> > + { PRE_DEVICE_B_1X, 0xC2 },
> > + { MAIN_DEVICE_C_1X, 0x83 },
> > + { COEFF_DEVICE_C_1X, 0xC3 },
> > + { PRE_DEVICE_C_1X, 0xC3 },
> > + { MAIN_DEVICE_D_1X, 0x84 },
> > + { COEFF_DEVICE_D_1X, 0xC4 },
> > + { PRE_DEVICE_D_1X, 0xC4 },
> > +};
> > +
> > +static const struct blktyp_devidx_map non_ppc3_mapping_table[] = {
> > + { MAIN_ALL_DEVICES, 0x80 },
> > + { MAIN_DEVICE_A, 0x81 },
> > + { COEFF_DEVICE_A, 0xC1 },
> > + { PRE_DEVICE_A, 0xC1 },
> > + { MAIN_DEVICE_B, 0x82 },
> > + { COEFF_DEVICE_B, 0xC2 },
> > + { PRE_DEVICE_B, 0xC2 },
> > + { MAIN_DEVICE_C, 0x83 },
> > + { COEFF_DEVICE_C, 0xC3 },
> > + { PRE_DEVICE_C, 0xC3 },
> > + { MAIN_DEVICE_D, 0x84 },
> > + { COEFF_DEVICE_D, 0xC4 },
> > + { PRE_DEVICE_D, 0xC4 },
> > +};
> > +
> > static struct tasdevice_config_info *tasdevice_add_config(
> > struct tasdevice_priv *tas_priv, unsigned char *config_data,
> > unsigned int config_size, int *status) @@ -316,6 +378,37 @@
> > int tasdevice_rca_parser(void *context, const struct firmware *fmw) }
> > EXPORT_SYMBOL_NS_GPL(tasdevice_rca_parser,
> SND_SOC_TAS2781_FMWLIB);
> >
> > +/* fixed m68k compiling issue: mapping table can save code field */
> > +static unsigned char map_dev_idx(struct tasdevice_fw *tas_fmw,
> > + struct tasdev_blk *block)
> > +{
> > +
> > + struct blktyp_devidx_map *p =
> > + (struct blktyp_devidx_map *)non_ppc3_mapping_table;
>
> Please do not cast away constness when not needed (also below).
>
> > + struct tasdevice_dspfw_hdr *fw_hdr = &(tas_fmw->fw_hdr);
> > + struct tasdevice_fw_fixed_hdr *fw_fixed_hdr =
> > + &(fw_hdr->fixed_hdr);
> > +
> > + int i, n = ARRAY_SIZE(non_ppc3_mapping_table);
>
> size_t
>
> > + unsigned char dev_idx = 0;
> > +
> > + if (fw_fixed_hdr->ppcver >= PPC3_VERSION_TAS2781) {
> > + p = (struct blktyp_devidx_map *)ppc3_tas2781_mapping_table;
> > + n = ARRAY_SIZE(ppc3_tas2781_mapping_table);
> > + } else if (fw_fixed_hdr->ppcver >= PPC3_VERSION) {
> > + p = (struct blktyp_devidx_map *)ppc3_mapping_table;
> > + n = ARRAY_SIZE(ppc3_mapping_table);
> > + }
> > +
> > + for (i = 0; i < n; i++) {
> > + if (block->type == p[i].blktyp) {
> > + dev_idx = p[i].dev_idx;
> > + break;
> > + }
> > + }
> > +
> > + return dev_idx;
> > +}
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-
> m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds