Re: [PATCH v6 5/7] ASoC: fsl_asrc: Move common definition to fsl_asrc_common
On Mon, Apr 13, 2020 at 12:31 PM Nicolin Chen wrote: > > On Mon, Apr 13, 2020 at 11:16:31AM +0800, Shengjiu Wang wrote: > > On Sun, Apr 12, 2020 at 10:08 AM Nicolin Chen > > wrote: > > > > > > On Sat, Apr 11, 2020 at 01:49:43PM +0800, Shengjiu Wang wrote: > > > > > > > > > diff --git a/sound/soc/fsl/fsl_asrc_dma.c > > > > > > b/sound/soc/fsl/fsl_asrc_dma.c > > > > > > index b15946e03380..5cf0468ce6e3 100644 > > > > > > --- a/sound/soc/fsl/fsl_asrc_dma.c > > > > > > +++ b/sound/soc/fsl/fsl_asrc_dma.c > > > > > > > > > > > @@ -311,11 +311,12 @@ static int fsl_asrc_dma_startup(struct > > > > > > snd_soc_component *component, > > > > > > return ret; > > > > > > } > > > > > > > > > > > > - pair = kzalloc(sizeof(struct fsl_asrc_pair), GFP_KERNEL); > > > > > > + pair = kzalloc(sizeof(struct fsl_asrc_pair) + > > > > > > PAIR_PRIVAT_SIZE, GFP_KERNEL); > > > > > > > > > > If we only use the PAIR_PRIVATE_SIZE here, maybe we can put the > > > > > define in this file too, rather than in the header file. > > > > > > > > > > And could fit 80 characters: > > > > > > > > > > + pair = kzalloc(sizeof(*pair) + PAIR_PRIVAT_SIZE, GFP_KERNEL); > > > > > > > I will use a function pointer > > > > int (*get_pair_priv_size)(void) > > > > > > Since it's the size of pair or cts structure, could be just a > > > size_t variable? > > > > Yes, should be "size_t (*get_pair_priv_size)(void)" > > Does it have to be a function? -- how about this: > > struct pair { > ... > size_t private_size; > void *private; > }; > > probe/or-somewhere() { > ... > pair->private = pair_priv; we need to know the size of pair_priv before allocate memory. > pair->private_size = sizeof(*pair_priv); > ... > } In fsl_asrc_dma_startup, we need to allocate memory for pair and pair->privateļ¼but we don't know the object, so we don't know the size of private, so function pointer is better. best regards wang shengjiu
Re: [PATCH v6 5/7] ASoC: fsl_asrc: Move common definition to fsl_asrc_common
On Mon, Apr 13, 2020 at 11:16:31AM +0800, Shengjiu Wang wrote: > On Sun, Apr 12, 2020 at 10:08 AM Nicolin Chen wrote: > > > > On Sat, Apr 11, 2020 at 01:49:43PM +0800, Shengjiu Wang wrote: > > > > > > > diff --git a/sound/soc/fsl/fsl_asrc_dma.c > > > > > b/sound/soc/fsl/fsl_asrc_dma.c > > > > > index b15946e03380..5cf0468ce6e3 100644 > > > > > --- a/sound/soc/fsl/fsl_asrc_dma.c > > > > > +++ b/sound/soc/fsl/fsl_asrc_dma.c > > > > > > > > > @@ -311,11 +311,12 @@ static int fsl_asrc_dma_startup(struct > > > > > snd_soc_component *component, > > > > > return ret; > > > > > } > > > > > > > > > > - pair = kzalloc(sizeof(struct fsl_asrc_pair), GFP_KERNEL); > > > > > + pair = kzalloc(sizeof(struct fsl_asrc_pair) + PAIR_PRIVAT_SIZE, > > > > > GFP_KERNEL); > > > > > > > > If we only use the PAIR_PRIVATE_SIZE here, maybe we can put the > > > > define in this file too, rather than in the header file. > > > > > > > > And could fit 80 characters: > > > > > > > > + pair = kzalloc(sizeof(*pair) + PAIR_PRIVAT_SIZE, GFP_KERNEL); > > > > > I will use a function pointer > > > int (*get_pair_priv_size)(void) > > > > Since it's the size of pair or cts structure, could be just a > > size_t variable? > > Yes, should be "size_t (*get_pair_priv_size)(void)" Does it have to be a function? -- how about this: struct pair { ... size_t private_size; void *private; }; probe/or-somewhere() { ... pair->private = pair_priv; pair->private_size = sizeof(*pair_priv); ... }
Re: [PATCH v6 5/7] ASoC: fsl_asrc: Move common definition to fsl_asrc_common
On Sun, Apr 12, 2020 at 10:08 AM Nicolin Chen wrote: > > On Sat, Apr 11, 2020 at 01:49:43PM +0800, Shengjiu Wang wrote: > > > > > diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c > > > > index b15946e03380..5cf0468ce6e3 100644 > > > > --- a/sound/soc/fsl/fsl_asrc_dma.c > > > > +++ b/sound/soc/fsl/fsl_asrc_dma.c > > > > > > > @@ -311,11 +311,12 @@ static int fsl_asrc_dma_startup(struct > > > > snd_soc_component *component, > > > > return ret; > > > > } > > > > > > > > - pair = kzalloc(sizeof(struct fsl_asrc_pair), GFP_KERNEL); > > > > + pair = kzalloc(sizeof(struct fsl_asrc_pair) + PAIR_PRIVAT_SIZE, > > > > GFP_KERNEL); > > > > > > If we only use the PAIR_PRIVATE_SIZE here, maybe we can put the > > > define in this file too, rather than in the header file. > > > > > > And could fit 80 characters: > > > > > > + pair = kzalloc(sizeof(*pair) + PAIR_PRIVAT_SIZE, GFP_KERNEL); > > > I will use a function pointer > > int (*get_pair_priv_size)(void) > > Since it's the size of pair or cts structure, could be just a > size_t variable? Yes, should be "size_t (*get_pair_priv_size)(void)" best regards wang shengjiu
Re: [PATCH v6 5/7] ASoC: fsl_asrc: Move common definition to fsl_asrc_common
On Sat, Apr 11, 2020 at 01:49:43PM +0800, Shengjiu Wang wrote: > > > diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c > > > index b15946e03380..5cf0468ce6e3 100644 > > > --- a/sound/soc/fsl/fsl_asrc_dma.c > > > +++ b/sound/soc/fsl/fsl_asrc_dma.c > > > > > @@ -311,11 +311,12 @@ static int fsl_asrc_dma_startup(struct > > > snd_soc_component *component, > > > return ret; > > > } > > > > > > - pair = kzalloc(sizeof(struct fsl_asrc_pair), GFP_KERNEL); > > > + pair = kzalloc(sizeof(struct fsl_asrc_pair) + PAIR_PRIVAT_SIZE, > > > GFP_KERNEL); > > > > If we only use the PAIR_PRIVATE_SIZE here, maybe we can put the > > define in this file too, rather than in the header file. > > > > And could fit 80 characters: > > > > + pair = kzalloc(sizeof(*pair) + PAIR_PRIVAT_SIZE, GFP_KERNEL); > I will use a function pointer > int (*get_pair_priv_size)(void) Since it's the size of pair or cts structure, could be just a size_t variable?
Re: [PATCH v6 5/7] ASoC: fsl_asrc: Move common definition to fsl_asrc_common
Hi On Tue, Apr 7, 2020 at 7:50 AM Nicolin Chen wrote: > > On Wed, Apr 01, 2020 at 04:45:38PM +0800, Shengjiu Wang wrote: > > > static int fsl_asrc_probe(struct platform_device *pdev) > > { > > struct device_node *np = pdev->dev.of_node; > > struct fsl_asrc *asrc; > > + struct fsl_asrc_priv *asrc_priv; > > Could we move it before "struct fsl_asrc *asrc;"? > > > diff --git a/sound/soc/fsl/fsl_asrc_common.h > > b/sound/soc/fsl/fsl_asrc_common.h > > new file mode 100644 > > index ..5c93ccdfc30a > > --- /dev/null > > +++ b/sound/soc/fsl/fsl_asrc_common.h > > > +#define PAIR_CTX_NUM 0x4 > > +#define PAIR_PRIVAT_SIZE 0x400 > > "PRIVAT_" => "PRIVATE_" > > > +/** > > + * fsl_asrc_pair: ASRC common data > > "fsl_asrc_pair" => "fsl_asrc" > > > + */ > > +struct fsl_asrc { > > > diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c > > index b15946e03380..5cf0468ce6e3 100644 > > --- a/sound/soc/fsl/fsl_asrc_dma.c > > +++ b/sound/soc/fsl/fsl_asrc_dma.c > > > @@ -311,11 +311,12 @@ static int fsl_asrc_dma_startup(struct > > snd_soc_component *component, > > return ret; > > } > > > > - pair = kzalloc(sizeof(struct fsl_asrc_pair), GFP_KERNEL); > > + pair = kzalloc(sizeof(struct fsl_asrc_pair) + PAIR_PRIVAT_SIZE, > > GFP_KERNEL); > > If we only use the PAIR_PRIVATE_SIZE here, maybe we can put the > define in this file too, rather than in the header file. > > And could fit 80 characters: > > + pair = kzalloc(sizeof(*pair) + PAIR_PRIVAT_SIZE, GFP_KERNEL); I will use a function pointer int (*get_pair_priv_size)(void) to avoid definition of PAIR_PRIVATE_SIZE. which is not safe. best regards wang shengjiu
Re: [PATCH v6 5/7] ASoC: fsl_asrc: Move common definition to fsl_asrc_common
On Wed, Apr 01, 2020 at 04:45:38PM +0800, Shengjiu Wang wrote: > static int fsl_asrc_probe(struct platform_device *pdev) > { > struct device_node *np = pdev->dev.of_node; > struct fsl_asrc *asrc; > + struct fsl_asrc_priv *asrc_priv; Could we move it before "struct fsl_asrc *asrc;"? > diff --git a/sound/soc/fsl/fsl_asrc_common.h b/sound/soc/fsl/fsl_asrc_common.h > new file mode 100644 > index ..5c93ccdfc30a > --- /dev/null > +++ b/sound/soc/fsl/fsl_asrc_common.h > +#define PAIR_CTX_NUM 0x4 > +#define PAIR_PRIVAT_SIZE 0x400 "PRIVAT_" => "PRIVATE_" > +/** > + * fsl_asrc_pair: ASRC common data "fsl_asrc_pair" => "fsl_asrc" > + */ > +struct fsl_asrc { > diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c > index b15946e03380..5cf0468ce6e3 100644 > --- a/sound/soc/fsl/fsl_asrc_dma.c > +++ b/sound/soc/fsl/fsl_asrc_dma.c > @@ -311,11 +311,12 @@ static int fsl_asrc_dma_startup(struct > snd_soc_component *component, > return ret; > } > > - pair = kzalloc(sizeof(struct fsl_asrc_pair), GFP_KERNEL); > + pair = kzalloc(sizeof(struct fsl_asrc_pair) + PAIR_PRIVAT_SIZE, > GFP_KERNEL); If we only use the PAIR_PRIVATE_SIZE here, maybe we can put the define in this file too, rather than in the header file. And could fit 80 characters: + pair = kzalloc(sizeof(*pair) + PAIR_PRIVAT_SIZE, GFP_KERNEL);