diff mbox series

[v2,13/16] rpmsg: virtio: probe the rpmsg_ctl device

Message ID 20201222105726.16906-14-arnaud.pouliquen@foss.st.com (mailing list archive)
State New, archived
Headers show
Series introduce generic IOCTL interface for RPMsg channels management | expand

Commit Message

Arnaud POULIQUEN Dec. 22, 2020, 10:57 a.m. UTC
Probe the rpmsg_ctl driver on virtio rpmsg bus creation.
This provides the possibility to expose an ioctrl to create
RPMsg channels.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
---
 drivers/rpmsg/virtio_rpmsg_bus.c | 37 +++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

Comments

kernel test robot Dec. 29, 2020, 4:16 a.m. UTC | #1
Hi Arnaud,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.11-rc1 next-20201223]
[cannot apply to rpmsg/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Arnaud-Pouliquen/introduce-generic-IOCTL-interface-for-RPMsg-channels-management/20201222-190521
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8653b778e454a7708847aeafe689bce07aeeb94e
config: x86_64-randconfig-a016-20201221 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project cee1e7d14f4628d6174b33640d502bff3b54ae45)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/532ff49403675dd41b19bcc2b03ca22a08443f8d
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Arnaud-Pouliquen/introduce-generic-IOCTL-interface-for-RPMsg-channels-management/20201222-190521
        git checkout 532ff49403675dd41b19bcc2b03ca22a08443f8d
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/rpmsg/virtio_rpmsg_bus.c:947:7: warning: variable 'rpdev_ctrl' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                   if (err)
                       ^~~
   drivers/rpmsg/virtio_rpmsg_bus.c:979:32: note: uninitialized use occurs here
           kfree(to_virtio_rpmsg_channel(rpdev_ctrl));
                                         ^~~~~~~~~~
   drivers/rpmsg/virtio_rpmsg_bus.c:111:15: note: expanded from macro 'to_virtio_rpmsg_channel'
           container_of(_rpdev, struct virtio_rpmsg_channel, rpdev)
                        ^~~~~~
   include/linux/kernel.h:693:26: note: expanded from macro 'container_of'
           void *__mptr = (void *)(ptr);                                   \
                                   ^~~
   drivers/rpmsg/virtio_rpmsg_bus.c:947:3: note: remove the 'if' if its condition is always false
                   if (err)
                   ^~~~~~~~
   drivers/rpmsg/virtio_rpmsg_bus.c:930:7: warning: variable 'rpdev_ctrl' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                   if (!vch) {
                       ^~~~
   drivers/rpmsg/virtio_rpmsg_bus.c:979:32: note: uninitialized use occurs here
           kfree(to_virtio_rpmsg_channel(rpdev_ctrl));
                                         ^~~~~~~~~~
   drivers/rpmsg/virtio_rpmsg_bus.c:111:15: note: expanded from macro 'to_virtio_rpmsg_channel'
           container_of(_rpdev, struct virtio_rpmsg_channel, rpdev)
                        ^~~~~~
   include/linux/kernel.h:693:26: note: expanded from macro 'container_of'
           void *__mptr = (void *)(ptr);                                   \
                                   ^~~
   drivers/rpmsg/virtio_rpmsg_bus.c:930:3: note: remove the 'if' if its condition is always false
                   if (!vch) {
                   ^~~~~~~~~~~
   drivers/rpmsg/virtio_rpmsg_bus.c:853:44: note: initialize the variable 'rpdev_ctrl' to silence this warning
           struct rpmsg_device *rpdev_ns, *rpdev_ctrl;
                                                     ^
                                                      = NULL
   2 warnings generated.


vim +947 drivers/rpmsg/virtio_rpmsg_bus.c

532ff49403675dd Arnaud Pouliquen     2020-12-22  845  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  846  static int rpmsg_probe(struct virtio_device *vdev)
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  847  {
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  848  	vq_callback_t *vq_cbs[] = { rpmsg_recv_done, rpmsg_xmit_done };
f7ad26ff952b3ca Stefan Hajnoczi      2015-12-17  849  	static const char * const names[] = { "input", "output" };
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  850  	struct virtqueue *vqs[2];
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  851  	struct virtproc_info *vrp;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  852  	struct virtio_rpmsg_channel *vch;
532ff49403675dd Arnaud Pouliquen     2020-12-22  853  	struct rpmsg_device *rpdev_ns, *rpdev_ctrl;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  854  	void *bufs_va;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  855  	int err = 0, i;
b1b9891441fa33f Suman Anna           2014-09-16  856  	size_t total_buf_space;
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  857  	bool notify;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  858  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  859  	vrp = kzalloc(sizeof(*vrp), GFP_KERNEL);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  860  	if (!vrp)
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  861  		return -ENOMEM;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  862  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  863  	vrp->vdev = vdev;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  864  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  865  	idr_init(&vrp->endpoints);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  866  	mutex_init(&vrp->endpoints_lock);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  867  	mutex_init(&vrp->tx_lock);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  868  	init_waitqueue_head(&vrp->sendq);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  869  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  870  	/* We expect two virtqueues, rx and tx (and in this order) */
9b2bbdb22758845 Michael S. Tsirkin   2017-03-06  871  	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  872  	if (err)
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  873  		goto free_vrp;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  874  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  875  	vrp->rvq = vqs[0];
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  876  	vrp->svq = vqs[1];
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  877  
b1b9891441fa33f Suman Anna           2014-09-16  878  	/* we expect symmetric tx/rx vrings */
b1b9891441fa33f Suman Anna           2014-09-16  879  	WARN_ON(virtqueue_get_vring_size(vrp->rvq) !=
b1b9891441fa33f Suman Anna           2014-09-16  880  		virtqueue_get_vring_size(vrp->svq));
b1b9891441fa33f Suman Anna           2014-09-16  881  
b1b9891441fa33f Suman Anna           2014-09-16  882  	/* we need less buffers if vrings are small */
b1b9891441fa33f Suman Anna           2014-09-16  883  	if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS / 2)
b1b9891441fa33f Suman Anna           2014-09-16  884  		vrp->num_bufs = virtqueue_get_vring_size(vrp->rvq) * 2;
b1b9891441fa33f Suman Anna           2014-09-16  885  	else
b1b9891441fa33f Suman Anna           2014-09-16  886  		vrp->num_bufs = MAX_RPMSG_NUM_BUFS;
b1b9891441fa33f Suman Anna           2014-09-16  887  
f93848f9eeb0f87 Loic Pallardy        2017-03-28  888  	vrp->buf_size = MAX_RPMSG_BUF_SIZE;
f93848f9eeb0f87 Loic Pallardy        2017-03-28  889  
f93848f9eeb0f87 Loic Pallardy        2017-03-28  890  	total_buf_space = vrp->num_bufs * vrp->buf_size;
b1b9891441fa33f Suman Anna           2014-09-16  891  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  892  	/* allocate coherent memory for the buffers */
d999b622fcfb392 Loic Pallardy        2019-01-10  893  	bufs_va = dma_alloc_coherent(vdev->dev.parent,
b1b9891441fa33f Suman Anna           2014-09-16  894  				     total_buf_space, &vrp->bufs_dma,
b1b9891441fa33f Suman Anna           2014-09-16  895  				     GFP_KERNEL);
3119b487e03650b Wei Yongjun          2013-04-29  896  	if (!bufs_va) {
3119b487e03650b Wei Yongjun          2013-04-29  897  		err = -ENOMEM;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  898  		goto vqs_del;
3119b487e03650b Wei Yongjun          2013-04-29  899  	}
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  900  
de4064af76537f1 Suman Anna           2018-10-23  901  	dev_dbg(&vdev->dev, "buffers: va %pK, dma %pad\n",
8d95b322ba34b15 Anna, Suman          2016-08-12  902  		bufs_va, &vrp->bufs_dma);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  903  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  904  	/* half of the buffers is dedicated for RX */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  905  	vrp->rbufs = bufs_va;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  906  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  907  	/* and half is dedicated for TX */
b1b9891441fa33f Suman Anna           2014-09-16  908  	vrp->sbufs = bufs_va + total_buf_space / 2;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  909  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  910  	/* set up the receive buffers */
b1b9891441fa33f Suman Anna           2014-09-16  911  	for (i = 0; i < vrp->num_bufs / 2; i++) {
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  912  		struct scatterlist sg;
f93848f9eeb0f87 Loic Pallardy        2017-03-28  913  		void *cpu_addr = vrp->rbufs + i * vrp->buf_size;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  914  
9dd87c2af651b09 Loic Pallardy        2017-03-28  915  		rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  916  
cee51d69a45b6ce Rusty Russell        2013-03-20  917  		err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr,
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  918  					  GFP_KERNEL);
57e1a37347d31c6 Rusty Russell        2012-10-16  919  		WARN_ON(err); /* sanity check; this can't really happen */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  920  	}
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  921  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  922  	/* suppress "tx-complete" interrupts */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  923  	virtqueue_disable_cb(vrp->svq);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  924  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  925  	vdev->priv = vrp;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  926  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  927  	/* if supported by the remote processor, enable the name service */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  928  	if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_NS)) {
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  929  		vch = kzalloc(sizeof(*vch), GFP_KERNEL);
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  930  		if (!vch) {
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  931  			err = -ENOMEM;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  932  			goto free_coherent;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  933  		}
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  934  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  935  		/* Link the channel to our vrp */
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  936  		vch->vrp = vrp;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  937  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  938  		/* Assign public information to the rpmsg_device */
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  939  		rpdev_ns = &vch->rpdev;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  940  		rpdev_ns->ops = &virtio_rpmsg_ops;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  941  		rpdev_ns->little_endian = virtio_is_little_endian(vrp->vdev);
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  942  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  943  		rpdev_ns->dev.parent = &vrp->vdev->dev;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  944  		rpdev_ns->dev.release = virtio_rpmsg_release_device;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  945  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  946  		err = rpmsg_ns_register_device(rpdev_ns);
950a7388f02bf77 Arnaud Pouliquen     2020-11-20 @947  		if (err)
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  948  			goto free_coherent;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  949  	}
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  950  
532ff49403675dd Arnaud Pouliquen     2020-12-22  951  	rpdev_ctrl = rpmsg_virtio_add_char_dev(vdev);
532ff49403675dd Arnaud Pouliquen     2020-12-22  952  	if (IS_ERR(rpdev_ctrl)) {
532ff49403675dd Arnaud Pouliquen     2020-12-22  953  		err = PTR_ERR(rpdev_ctrl);
532ff49403675dd Arnaud Pouliquen     2020-12-22  954  		goto free_coherent;
532ff49403675dd Arnaud Pouliquen     2020-12-22  955  	}
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  956  	/*
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  957  	 * Prepare to kick but don't notify yet - we can't do this before
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  958  	 * device is ready.
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  959  	 */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  960  	notify = virtqueue_kick_prepare(vrp->rvq);
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  961  
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  962  	/* From this point on, we can notify and get callbacks. */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  963  	virtio_device_ready(vdev);
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  964  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  965  	/* tell the remote processor it can start sending messages */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  966  	/*
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  967  	 * this might be concurrent with callbacks, but we are only
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  968  	 * doing notify, not a full kick here, so that's ok.
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  969  	 */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  970  	if (notify)
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  971  		virtqueue_notify(vrp->rvq);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  972  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  973  	dev_info(&vdev->dev, "rpmsg host is online\n");
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  974  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  975  	return 0;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  976  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  977  free_coherent:
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  978  	kfree(vch);
532ff49403675dd Arnaud Pouliquen     2020-12-22  979  	kfree(to_virtio_rpmsg_channel(rpdev_ctrl));
d999b622fcfb392 Loic Pallardy        2019-01-10  980  	dma_free_coherent(vdev->dev.parent, total_buf_space,
eeb0074f36d1ab0 Fernando Guzman Lugo 2012-08-29  981  			  bufs_va, vrp->bufs_dma);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  982  vqs_del:
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  983  	vdev->config->del_vqs(vrp->vdev);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  984  free_vrp:
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  985  	kfree(vrp);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  986  	return err;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  987  }
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  988  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Dan Carpenter Jan. 4, 2021, 12:59 p.m. UTC | #2
Hi Arnaud,

url:    https://github.com/0day-ci/linux/commits/Arnaud-Pouliquen/introduce-generic-IOCTL-interface-for-RPMsg-channels-management/20201222-190521
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8653b778e454a7708847aeafe689bce07aeeb94e
config: x86_64-randconfig-m001-20201221 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/rpmsg/virtio_rpmsg_bus.c:978 rpmsg_probe() error: uninitialized symbol 'vch'.
drivers/rpmsg/virtio_rpmsg_bus.c:979 rpmsg_probe() error: uninitialized symbol 'rpdev_ctrl'.

vim +/vch +978 drivers/rpmsg/virtio_rpmsg_bus.c

bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  846  static int rpmsg_probe(struct virtio_device *vdev)
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  847  {
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  848  	vq_callback_t *vq_cbs[] = { rpmsg_recv_done, rpmsg_xmit_done };
f7ad26ff952b3ca Stefan Hajnoczi      2015-12-17  849  	static const char * const names[] = { "input", "output" };
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  850  	struct virtqueue *vqs[2];
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  851  	struct virtproc_info *vrp;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  852  	struct virtio_rpmsg_channel *vch;
                                                                                     ^^^
532ff49403675dd Arnaud Pouliquen     2020-12-22  853  	struct rpmsg_device *rpdev_ns, *rpdev_ctrl;
                                                                                        ^^^^^^^^^^

bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  854  	void *bufs_va;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  855  	int err = 0, i;
b1b9891441fa33f Suman Anna           2014-09-16  856  	size_t total_buf_space;
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  857  	bool notify;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  858  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  859  	vrp = kzalloc(sizeof(*vrp), GFP_KERNEL);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  860  	if (!vrp)
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  861  		return -ENOMEM;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  862  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  863  	vrp->vdev = vdev;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  864  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  865  	idr_init(&vrp->endpoints);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  866  	mutex_init(&vrp->endpoints_lock);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  867  	mutex_init(&vrp->tx_lock);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  868  	init_waitqueue_head(&vrp->sendq);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  869  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  870  	/* We expect two virtqueues, rx and tx (and in this order) */
9b2bbdb22758845 Michael S. Tsirkin   2017-03-06  871  	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  872  	if (err)
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  873  		goto free_vrp;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  874  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  875  	vrp->rvq = vqs[0];
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  876  	vrp->svq = vqs[1];
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  877  
b1b9891441fa33f Suman Anna           2014-09-16  878  	/* we expect symmetric tx/rx vrings */
b1b9891441fa33f Suman Anna           2014-09-16  879  	WARN_ON(virtqueue_get_vring_size(vrp->rvq) !=
b1b9891441fa33f Suman Anna           2014-09-16  880  		virtqueue_get_vring_size(vrp->svq));
b1b9891441fa33f Suman Anna           2014-09-16  881  
b1b9891441fa33f Suman Anna           2014-09-16  882  	/* we need less buffers if vrings are small */
b1b9891441fa33f Suman Anna           2014-09-16  883  	if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS / 2)
b1b9891441fa33f Suman Anna           2014-09-16  884  		vrp->num_bufs = virtqueue_get_vring_size(vrp->rvq) * 2;
b1b9891441fa33f Suman Anna           2014-09-16  885  	else
b1b9891441fa33f Suman Anna           2014-09-16  886  		vrp->num_bufs = MAX_RPMSG_NUM_BUFS;
b1b9891441fa33f Suman Anna           2014-09-16  887  
f93848f9eeb0f87 Loic Pallardy        2017-03-28  888  	vrp->buf_size = MAX_RPMSG_BUF_SIZE;
f93848f9eeb0f87 Loic Pallardy        2017-03-28  889  
f93848f9eeb0f87 Loic Pallardy        2017-03-28  890  	total_buf_space = vrp->num_bufs * vrp->buf_size;
b1b9891441fa33f Suman Anna           2014-09-16  891  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  892  	/* allocate coherent memory for the buffers */
d999b622fcfb392 Loic Pallardy        2019-01-10  893  	bufs_va = dma_alloc_coherent(vdev->dev.parent,
b1b9891441fa33f Suman Anna           2014-09-16  894  				     total_buf_space, &vrp->bufs_dma,
b1b9891441fa33f Suman Anna           2014-09-16  895  				     GFP_KERNEL);
3119b487e03650b Wei Yongjun          2013-04-29  896  	if (!bufs_va) {
3119b487e03650b Wei Yongjun          2013-04-29  897  		err = -ENOMEM;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  898  		goto vqs_del;
3119b487e03650b Wei Yongjun          2013-04-29  899  	}
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  900  
de4064af76537f1 Suman Anna           2018-10-23  901  	dev_dbg(&vdev->dev, "buffers: va %pK, dma %pad\n",
8d95b322ba34b15 Anna, Suman          2016-08-12  902  		bufs_va, &vrp->bufs_dma);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  903  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  904  	/* half of the buffers is dedicated for RX */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  905  	vrp->rbufs = bufs_va;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  906  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  907  	/* and half is dedicated for TX */
b1b9891441fa33f Suman Anna           2014-09-16  908  	vrp->sbufs = bufs_va + total_buf_space / 2;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  909  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  910  	/* set up the receive buffers */
b1b9891441fa33f Suman Anna           2014-09-16  911  	for (i = 0; i < vrp->num_bufs / 2; i++) {
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  912  		struct scatterlist sg;
f93848f9eeb0f87 Loic Pallardy        2017-03-28  913  		void *cpu_addr = vrp->rbufs + i * vrp->buf_size;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  914  
9dd87c2af651b09 Loic Pallardy        2017-03-28  915  		rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  916  
cee51d69a45b6ce Rusty Russell        2013-03-20  917  		err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr,
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  918  					  GFP_KERNEL);
57e1a37347d31c6 Rusty Russell        2012-10-16  919  		WARN_ON(err); /* sanity check; this can't really happen */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  920  	}
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  921  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  922  	/* suppress "tx-complete" interrupts */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  923  	virtqueue_disable_cb(vrp->svq);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  924  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  925  	vdev->priv = vrp;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  926  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  927  	/* if supported by the remote processor, enable the name service */
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  928  	if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_NS)) {
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  929  		vch = kzalloc(sizeof(*vch), GFP_KERNEL);

Not initialized if virtio_has_feature() is false.

950a7388f02bf77 Arnaud Pouliquen     2020-11-20  930  		if (!vch) {
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  931  			err = -ENOMEM;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  932  			goto free_coherent;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  933  		}
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  934  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  935  		/* Link the channel to our vrp */
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  936  		vch->vrp = vrp;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  937  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  938  		/* Assign public information to the rpmsg_device */
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  939  		rpdev_ns = &vch->rpdev;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  940  		rpdev_ns->ops = &virtio_rpmsg_ops;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  941  		rpdev_ns->little_endian = virtio_is_little_endian(vrp->vdev);
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  942  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  943  		rpdev_ns->dev.parent = &vrp->vdev->dev;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  944  		rpdev_ns->dev.release = virtio_rpmsg_release_device;
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  945  
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  946  		err = rpmsg_ns_register_device(rpdev_ns);
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  947  		if (err)
950a7388f02bf77 Arnaud Pouliquen     2020-11-20  948  			goto free_coherent;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  949  	}
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  950  
532ff49403675dd Arnaud Pouliquen     2020-12-22  951  	rpdev_ctrl = rpmsg_virtio_add_char_dev(vdev);
532ff49403675dd Arnaud Pouliquen     2020-12-22  952  	if (IS_ERR(rpdev_ctrl)) {
532ff49403675dd Arnaud Pouliquen     2020-12-22  953  		err = PTR_ERR(rpdev_ctrl);
532ff49403675dd Arnaud Pouliquen     2020-12-22  954  		goto free_coherent;
532ff49403675dd Arnaud Pouliquen     2020-12-22  955  	}
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  956  	/*
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  957  	 * Prepare to kick but don't notify yet - we can't do this before
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  958  	 * device is ready.
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  959  	 */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  960  	notify = virtqueue_kick_prepare(vrp->rvq);
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  961  
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  962  	/* From this point on, we can notify and get callbacks. */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  963  	virtio_device_ready(vdev);
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  964  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  965  	/* tell the remote processor it can start sending messages */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  966  	/*
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  967  	 * this might be concurrent with callbacks, but we are only
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  968  	 * doing notify, not a full kick here, so that's ok.
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  969  	 */
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  970  	if (notify)
71e4b8bf0482fc7 Michael S. Tsirkin   2015-03-12  971  		virtqueue_notify(vrp->rvq);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  972  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  973  	dev_info(&vdev->dev, "rpmsg host is online\n");
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  974  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  975  	return 0;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  976  
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  977  free_coherent:
950a7388f02bf77 Arnaud Pouliquen     2020-11-20 @978  	kfree(vch);
                                                        ^^^^^^^^^^^

532ff49403675dd Arnaud Pouliquen     2020-12-22 @979  	kfree(to_virtio_rpmsg_channel(rpdev_ctrl));
                                                                                      ^^^^^^^^^^

d999b622fcfb392 Loic Pallardy        2019-01-10  980  	dma_free_coherent(vdev->dev.parent, total_buf_space,
eeb0074f36d1ab0 Fernando Guzman Lugo 2012-08-29  981  			  bufs_va, vrp->bufs_dma);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  982  vqs_del:
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  983  	vdev->config->del_vqs(vrp->vdev);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  984  free_vrp:
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  985  	kfree(vrp);
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  986  	return err;
bcabbccabffe732 Ohad Ben-Cohen       2011-10-20  987  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index c1d4bc08b2a5..e8caccb2d298 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -814,6 +814,35 @@  static void rpmsg_xmit_done(struct virtqueue *svq)
 	wake_up_interruptible(&vrp->sendq);
 }
 
+static struct rpmsg_device *rpmsg_virtio_add_char_dev(struct virtio_device *vdev)
+{
+	struct virtproc_info *vrp = vdev->priv;
+	struct virtio_rpmsg_channel *vch;
+	struct rpmsg_device *rpdev_ctrl;
+	int err = 0;
+
+	vch = kzalloc(sizeof(*vch), GFP_KERNEL);
+	if (!vch)
+		return ERR_PTR(-ENOMEM);
+
+	/* Link the channel to our vrp */
+	vch->vrp = vrp;
+
+	/* Assign public information to the rpmsg_device */
+	rpdev_ctrl = &vch->rpdev;
+	rpdev_ctrl->ops = &virtio_rpmsg_ops;
+
+	rpdev_ctrl->dev.parent = &vrp->vdev->dev;
+	rpdev_ctrl->dev.release = virtio_rpmsg_release_device;
+	rpdev_ctrl->little_endian = virtio_is_little_endian(vrp->vdev);
+
+	err = rpmsg_ctl_register_device(rpdev_ctrl);
+	if (err)
+		return ERR_PTR(err);
+
+	return rpdev_ctrl;
+}
+
 static int rpmsg_probe(struct virtio_device *vdev)
 {
 	vq_callback_t *vq_cbs[] = { rpmsg_recv_done, rpmsg_xmit_done };
@@ -821,7 +850,7 @@  static int rpmsg_probe(struct virtio_device *vdev)
 	struct virtqueue *vqs[2];
 	struct virtproc_info *vrp;
 	struct virtio_rpmsg_channel *vch;
-	struct rpmsg_device *rpdev_ns;
+	struct rpmsg_device *rpdev_ns, *rpdev_ctrl;
 	void *bufs_va;
 	int err = 0, i;
 	size_t total_buf_space;
@@ -919,6 +948,11 @@  static int rpmsg_probe(struct virtio_device *vdev)
 			goto free_coherent;
 	}
 
+	rpdev_ctrl = rpmsg_virtio_add_char_dev(vdev);
+	if (IS_ERR(rpdev_ctrl)) {
+		err = PTR_ERR(rpdev_ctrl);
+		goto free_coherent;
+	}
 	/*
 	 * Prepare to kick but don't notify yet - we can't do this before
 	 * device is ready.
@@ -942,6 +976,7 @@  static int rpmsg_probe(struct virtio_device *vdev)
 
 free_coherent:
 	kfree(vch);
+	kfree(to_virtio_rpmsg_channel(rpdev_ctrl));
 	dma_free_coherent(vdev->dev.parent, total_buf_space,
 			  bufs_va, vrp->bufs_dma);
 vqs_del: