[PATCH v6 01/10] mhi: Add mhi_controller_initialize helper

Manivannan Sadhasivam manivannan.sadhasivam at linaro.org
Thu Dec 31 01:48:05 EST 2020


Hi Loic,

+ath11k, kalle

On Tue, Dec 29, 2020 at 09:43:42AM +0100, Loic Poulain wrote:
> This function allows to initialize a mhi_controller structure.
> Today, it only zeroing the structure.
> 
> Use this function from mhi_alloc_controller so that any further
> initialization can be factorized in initalize function.
> 

I know that this has been discussed in earlier revisions but I'm still not
convinced to have 2 APIs doing a similar job. Since we don't have any usecase
currently to initialize extra fields other than the struct, we should be using
the alloc_controller API.

If you want to have a devres managed allocation, then the API should be extended
as below:

struct mhi_controller *mhi_alloc_controller(struct device *dev)
{
	struct mhi_controller *mhi_cntrl;

	if (!dev)
		mhi_cntrl = kzalloc(sizeof(*mhi_cntrl), GFP_KERNEL);
	else
		mhi_cntrl = devm_kzalloc(dev, sizeof(*mhi_cntrl), GFP_KERNEL);

	return mhi_cntrl;		
}

In this case, the ath11k MHI controller also need to be adjusted but we can use
the same immutable branch way.

Thanks,
Mani

> Signed-off-by: Loic Poulain <loic.poulain at linaro.org>
> ---
>  drivers/bus/mhi/core/init.c | 6 ++++++
>  include/linux/mhi.h         | 6 ++++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c
> index 96cde9c..a75ab8c 100644
> --- a/drivers/bus/mhi/core/init.c
> +++ b/drivers/bus/mhi/core/init.c
> @@ -1021,6 +1021,12 @@ void mhi_unregister_controller(struct mhi_controller *mhi_cntrl)
>  }
>  EXPORT_SYMBOL_GPL(mhi_unregister_controller);
>  
> +void mhi_initialize_controller(struct mhi_controller *mhi_cntrl)
> +{
> +	memset(mhi_cntrl, 0, sizeof(*mhi_cntrl));
> +}
> +EXPORT_SYMBOL_GPL(mhi_initialize_controller);
> +
>  struct mhi_controller *mhi_alloc_controller(void)
>  {
>  	struct mhi_controller *mhi_cntrl;
> diff --git a/include/linux/mhi.h b/include/linux/mhi.h
> index 04cf7f3..2754742 100644
> --- a/include/linux/mhi.h
> +++ b/include/linux/mhi.h
> @@ -537,6 +537,12 @@ struct mhi_driver {
>  #define to_mhi_device(dev) container_of(dev, struct mhi_device, dev)
>  
>  /**
> + * mhi_initialize_controller - Initialize MHI Controller structure
> + * @mhi_cntrl: MHI controller structure to initialize
> + */
> +void mhi_initialize_controller(struct mhi_controller *mhi_cntrl);
> +
> +/**
>   * mhi_alloc_controller - Allocate the MHI Controller structure
>   * Allocate the mhi_controller structure using zero initialized memory
>   */
> -- 
> 2.7.4
> 



More information about the ath11k mailing list