From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: "allen-kh.cheng" <allen-kh.cheng@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>,
tzungbi@google.com, cujomalainey@google.com,
Liam Girdwood <lgirdwood@gmail.com>,
Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Daniel Baluta <daniel.baluta@nxp.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Project_Global_Chrome_Upstream_Group@mediatek.com,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
sound-open-firmware@alsa-project.org
Subject: Re: [PATCH] firmware: mediatek: add adsp ipc protocol interface
Date: Tue, 11 Jan 2022 11:02:03 -0600 [thread overview]
Message-ID: <91eef4c9-adda-1921-16b5-af181b30d36e@linux.intel.com> (raw)
In-Reply-To: <20220111071011.5964-1-allen-kh.cheng@mediatek.com>
> +int mtk_adsp_ipc_send(struct mtk_adsp_ipc *ipc, unsigned int idx, uint32_t msg)
> +{
> + struct mtk_adsp_chan *dsp_chan;
> + int ret;
> +
> + if (idx >= MTK_ADSP_MBOX_NUM)
> + return -EINVAL;
> +
> + dsp_chan = &ipc->chans[idx];
> + ret = mbox_send_message(dsp_chan->ch, &msg);
> + if (ret < 0)
> + return ret;
> +
> + return 0;
this can be simplified a bit without the 'ret' variable
return mbox_send_message(dsp_chan->ch, &msg);
> +}
> +EXPORT_SYMBOL(mtk_adsp_ipc_send);
> +static int mtk_adsp_ipc_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct mtk_adsp_ipc *dsp_ipc;
> + struct mtk_adsp_chan *dsp_chan;
> + struct mbox_client *cl;
> + char *chan_name;
> + int ret;
> + int i, j;
> +
> + device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);
> +
> + dsp_ipc = devm_kzalloc(dev, sizeof(*dsp_ipc), GFP_KERNEL);
> + if (!dsp_ipc)
> + return -ENOMEM;
> +
> + for (i = 0; i < MTK_ADSP_MBOX_NUM; i++) {
> + chan_name = kasprintf(GFP_KERNEL, "mbox%d", i);
> + if (!chan_name) {
> + ret = -ENOMEM;
> + goto out;
> + }
in this case with the existing code you will free something that was not
allocated. It's not super elegant, consider using different labels as
suggested below.
> +
> + dsp_chan = &dsp_ipc->chans[i];
> + cl = &dsp_chan->cl;
> + cl->dev = dev->parent;
> + cl->tx_block = false;
> + cl->knows_txdone = false;
> + cl->tx_prepare = NULL;
> + cl->rx_callback = mtk_adsp_ipc_recv;
> +
> + dsp_chan->ipc = dsp_ipc;
> + dsp_chan->idx = i;
> + dsp_chan->ch = mbox_request_channel_byname(cl, chan_name);
> + if (IS_ERR(dsp_chan->ch)) {
> + ret = PTR_ERR(dsp_chan->ch);
> + if (ret != -EPROBE_DEFER)
> + dev_err(dev, "Failed to request mbox chan %d ret %d\n",
> + i, ret);
> + goto out;
goto out_free;
> + }
> +
> + dev_dbg(dev, "request mbox chan %s\n", chan_name);
> + kfree(chan_name);
> + }
> +
> + dsp_ipc->dev = dev;
> + dev_set_drvdata(dev, dsp_ipc);
> + dev_dbg(dev, "MTK ADSP IPC initialized\n");
> +
> + return 0;
> +
> +out:
out_free:
> + kfree(chan_name);
out:
> + for (j = 0; j < i; j++) {
> + dsp_chan = &dsp_ipc->chans[j];
> + mbox_free_channel(dsp_chan->ch);
> + }
> +
> + return ret;
> +}
> +
> +static int mtk_adsp_ipc_remove(struct platform_device *pdev)
> +{
> + struct mtk_adsp_ipc *dsp_ipc = dev_get_drvdata(&pdev->dev);
> + struct mtk_adsp_chan *dsp_chan;
> + int i;
> +
> + for (i = 0; i < MTK_ADSP_MBOX_NUM; i++) {
> + dsp_chan = &dsp_ipc->chans[i];
> + mbox_free_channel(dsp_chan->ch);
> + }
> +
> + return 0;
> +}
> +
> +static struct platform_driver mtk_adsp_ipc_driver = {
> + .driver = {
> + .name = "mtk-adsp-ipc",
> + },
> + .probe = mtk_adsp_ipc_probe,
> + .remove = mtk_adsp_ipc_remove,
> +};
> +builtin_platform_driver(mtk_adsp_ipc_driver);
> +
> +MODULE_AUTHOR("Allen-KH Cheng <allen-kh.cheng@mediatek.com>");
> +MODULE_DESCRIPTION("MTK ADSP IPC Driver");
> +MODULE_LICENSE("GPL v2");
the v2 here isn't useful, the license information can be found in the
SPDX line.
MODULE_LICENSE("GPL");
parent reply other threads:[~2022-01-11 17:25 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20220111071011.5964-1-allen-kh.cheng@mediatek.com>]
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=91eef4c9-adda-1921-16b5-af181b30d36e@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=allen-kh.cheng@mediatek.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=cujomalainey@google.com \
--cc=daniel.baluta@nxp.com \
--cc=devicetree@vger.kernel.org \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=ranjani.sridharan@linux.intel.com \
--cc=sound-open-firmware@alsa-project.org \
--cc=tiwai@suse.com \
--cc=tzungbi@google.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).