diff mbox series

[v3,11/12] misc: fastrpc: Add dma handle implementation

Message ID 20220126135304.16340-12-srinivas.kandagatla@linaro.org (mailing list archive)
State Not Applicable
Headers show
Series misc: fastrpc: Add missing DSP FastRPC features | expand

Commit Message

Srinivas Kandagatla Jan. 26, 2022, 1:53 p.m. UTC
From: Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>

The remote arguments carry both remote buffers and dma handles. Add proper
dma handle instructions to make it compatible with DSP implementation.

Signed-off-by: Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 52 +++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 19 deletions(-)

Comments

kernel test robot Jan. 26, 2022, 8:13 p.m. UTC | #1
Hi Srinivas,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on robh/for-next linux/master linus/master v5.17-rc1 next-20220125]
[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/Srinivas-Kandagatla/misc-fastrpc-Add-missing-DSP-FastRPC-features/20220126-215705
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 515a2f507491e7c3818e74ef4f4e088c1fecb190
config: hexagon-randconfig-r041-20220124 (https://download.01.org/0day-ci/archive/20220127/202201270440.GvskN5kg-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 2a1b7aa016c0f4b5598806205bdfbab1ea2d92c4)
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
        # https://github.com/0day-ci/linux/commit/70d5973b9373ab26b6a1ed520ee07b71c7bdba63
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Srinivas-Kandagatla/misc-fastrpc-Add-missing-DSP-FastRPC-features/20220126-215705
        git checkout 70d5973b9373ab26b6a1ed520ee07b71c7bdba63
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/misc/

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/misc/fastrpc.c:1862:13: warning: stack frame size (1256) exceeds limit (1024) in 'fastrpc_device_ioctl' [-Wframe-larger-than]
   static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,
               ^
   1 warning generated.


vim +/fastrpc_device_ioctl +1862 drivers/misc/fastrpc.c

b1c0b7969aa4918 Jeya R              2022-01-26  1861  
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08 @1862  static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1863  				 unsigned long arg)
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1864  {
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1865  	struct fastrpc_user *fl = (struct fastrpc_user *)file->private_data;
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1866  	char __user *argp = (char __user *)arg;
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1867  	int err;
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1868  
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1869  	switch (cmd) {
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1870  	case FASTRPC_IOCTL_INVOKE:
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1871  		err = fastrpc_invoke(fl, argp);
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1872  		break;
d73f71c7c6ee158 Srinivas Kandagatla 2019-02-08  1873  	case FASTRPC_IOCTL_INIT_ATTACH:
6010d9befc8df89 Jonathan Marek      2020-09-08  1874  		err = fastrpc_init_attach(fl, AUDIO_PD);
6010d9befc8df89 Jonathan Marek      2020-09-08  1875  		break;
6010d9befc8df89 Jonathan Marek      2020-09-08  1876  	case FASTRPC_IOCTL_INIT_ATTACH_SNS:
6010d9befc8df89 Jonathan Marek      2020-09-08  1877  		err = fastrpc_init_attach(fl, SENSORS_PD);
d73f71c7c6ee158 Srinivas Kandagatla 2019-02-08  1878  		break;
d73f71c7c6ee158 Srinivas Kandagatla 2019-02-08  1879  	case FASTRPC_IOCTL_INIT_CREATE:
d73f71c7c6ee158 Srinivas Kandagatla 2019-02-08  1880  		err = fastrpc_init_create_process(fl, argp);
d73f71c7c6ee158 Srinivas Kandagatla 2019-02-08  1881  		break;
6cffd79504ce040 Srinivas Kandagatla 2019-02-08  1882  	case FASTRPC_IOCTL_ALLOC_DMA_BUFF:
6cffd79504ce040 Srinivas Kandagatla 2019-02-08  1883  		err = fastrpc_dmabuf_alloc(fl, argp);
6cffd79504ce040 Srinivas Kandagatla 2019-02-08  1884  		break;
2419e55e532de14 Jorge Ramirez-Ortiz 2019-10-09  1885  	case FASTRPC_IOCTL_MMAP:
2419e55e532de14 Jorge Ramirez-Ortiz 2019-10-09  1886  		err = fastrpc_req_mmap(fl, argp);
2419e55e532de14 Jorge Ramirez-Ortiz 2019-10-09  1887  		break;
2419e55e532de14 Jorge Ramirez-Ortiz 2019-10-09  1888  	case FASTRPC_IOCTL_MUNMAP:
2419e55e532de14 Jorge Ramirez-Ortiz 2019-10-09  1889  		err = fastrpc_req_munmap(fl, argp);
2419e55e532de14 Jorge Ramirez-Ortiz 2019-10-09  1890  		break;
b1c0b7969aa4918 Jeya R              2022-01-26  1891  	case FASTRPC_IOCTL_MEM_MAP:
b1c0b7969aa4918 Jeya R              2022-01-26  1892  		err = fastrpc_req_mem_map(fl, argp);
b1c0b7969aa4918 Jeya R              2022-01-26  1893  		break;
b1c0b7969aa4918 Jeya R              2022-01-26  1894  	case FASTRPC_IOCTL_MEM_UNMAP:
b1c0b7969aa4918 Jeya R              2022-01-26  1895  		err = fastrpc_req_mem_unmap(fl, argp);
b1c0b7969aa4918 Jeya R              2022-01-26  1896  		break;
a22465bb4904fac Jeya R              2022-01-26  1897  	case FASTRPC_IOCTL_GET_DSP_INFO:
a22465bb4904fac Jeya R              2022-01-26  1898  		err = fastrpc_get_dsp_info(fl, argp);
a22465bb4904fac Jeya R              2022-01-26  1899  		break;
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1900  	default:
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1901  		err = -ENOTTY;
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1902  		break;
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1903  	}
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1904  
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1905  	return err;
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1906  }
c68cfb718c8f97b Srinivas Kandagatla 2019-02-08  1907  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Jan. 26, 2022, 8:14 p.m. UTC | #2
Hi Srinivas,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on robh/for-next linux/master linus/master v5.17-rc1 next-20220125]
[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/Srinivas-Kandagatla/misc-fastrpc-Add-missing-DSP-FastRPC-features/20220126-215705
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 515a2f507491e7c3818e74ef4f4e088c1fecb190
config: arc-randconfig-r003-20220126 (https://download.01.org/0day-ci/archive/20220127/202201270412.QDMYUTEr-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 11.2.0
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
        # https://github.com/0day-ci/linux/commit/70d5973b9373ab26b6a1ed520ee07b71c7bdba63
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Srinivas-Kandagatla/misc-fastrpc-Add-missing-DSP-FastRPC-features/20220126-215705
        git checkout 70d5973b9373ab26b6a1ed520ee07b71c7bdba63
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash drivers/misc/

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/misc/fastrpc.c: In function 'fastrpc_req_mem_unmap_impl':
   drivers/misc/fastrpc.c:1761:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    1761 |         args[0].ptr = (u64) &req_msg;
         |                       ^
   drivers/misc/fastrpc.c: In function 'fastrpc_req_mem_map':
   drivers/misc/fastrpc.c:1811:19: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
    1811 |         map->va = (void *) req.vaddrin;
         |                   ^
   drivers/misc/fastrpc.c:1816:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    1816 |         args[0].ptr = (u64) &req_msg;
         |                       ^
   drivers/misc/fastrpc.c:1822:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    1822 |         args[1].ptr = (u64) &pages;
         |                       ^
   drivers/misc/fastrpc.c:1825:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    1825 |         args[2].ptr = (u64) &pages;
         |                       ^
   drivers/misc/fastrpc.c:1828:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    1828 |         args[3].ptr = (u64) &rsp_msg;
         |                       ^
   drivers/misc/fastrpc.c: In function 'fastrpc_get_info_from_kernel.constprop':
>> drivers/misc/fastrpc.c:1552:1: warning: the frame size of 1076 bytes is larger than 1024 bytes [-Wframe-larger-than=]
    1552 | }
         | ^


vim +1552 drivers/misc/fastrpc.c

a22465bb4904fac Jeya R 2022-01-26  1515  
a22465bb4904fac Jeya R 2022-01-26  1516  static int fastrpc_get_info_from_kernel(struct fastrpc_ioctl_capability *cap,
a22465bb4904fac Jeya R 2022-01-26  1517  					struct fastrpc_user *fl)
a22465bb4904fac Jeya R 2022-01-26  1518  {
a22465bb4904fac Jeya R 2022-01-26  1519  	struct fastrpc_channel_ctx *cctx = fl->cctx;
a22465bb4904fac Jeya R 2022-01-26  1520  	uint32_t attribute_id = cap->attribute_id;
a22465bb4904fac Jeya R 2022-01-26  1521  	uint32_t dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
a22465bb4904fac Jeya R 2022-01-26  1522  	unsigned long flags;
a22465bb4904fac Jeya R 2022-01-26  1523  	uint32_t domain = cap->domain;
a22465bb4904fac Jeya R 2022-01-26  1524  	int err;
a22465bb4904fac Jeya R 2022-01-26  1525  
a22465bb4904fac Jeya R 2022-01-26  1526  	spin_lock_irqsave(&cctx->lock, flags);
a22465bb4904fac Jeya R 2022-01-26  1527  	/* check if we already have queried dsp for attributes */
a22465bb4904fac Jeya R 2022-01-26  1528  	if (cctx->valid_attributes) {
a22465bb4904fac Jeya R 2022-01-26  1529  		spin_unlock_irqrestore(&cctx->lock, flags);
a22465bb4904fac Jeya R 2022-01-26  1530  		goto done;
a22465bb4904fac Jeya R 2022-01-26  1531  	}
a22465bb4904fac Jeya R 2022-01-26  1532  	spin_unlock_irqrestore(&cctx->lock, flags);
a22465bb4904fac Jeya R 2022-01-26  1533  
a22465bb4904fac Jeya R 2022-01-26  1534  	err = fastrpc_get_info_from_dsp(fl, &dsp_attributes[0], FASTRPC_MAX_DSP_ATTRIBUTES);
a22465bb4904fac Jeya R 2022-01-26  1535  	if (err == DSP_UNSUPPORTED_API) {
a22465bb4904fac Jeya R 2022-01-26  1536  		dev_info(&cctx->rpdev->dev,
a22465bb4904fac Jeya R 2022-01-26  1537  			 "Warning: DSP capabilities not supported on domain: %d\n", domain);
a22465bb4904fac Jeya R 2022-01-26  1538  		return -EOPNOTSUPP;
a22465bb4904fac Jeya R 2022-01-26  1539  	} else if (err) {
a22465bb4904fac Jeya R 2022-01-26  1540  		dev_err(&cctx->rpdev->dev, "Error: dsp information is incorrect err: %d\n", err);
a22465bb4904fac Jeya R 2022-01-26  1541  		return err;
a22465bb4904fac Jeya R 2022-01-26  1542  	}
a22465bb4904fac Jeya R 2022-01-26  1543  
a22465bb4904fac Jeya R 2022-01-26  1544  	spin_lock_irqsave(&cctx->lock, flags);
a22465bb4904fac Jeya R 2022-01-26  1545  	memcpy(cctx->dsp_attributes, dsp_attributes, sizeof(u32) * FASTRPC_MAX_DSP_ATTRIBUTES);
a22465bb4904fac Jeya R 2022-01-26  1546  	cctx->valid_attributes = true;
a22465bb4904fac Jeya R 2022-01-26  1547  	spin_unlock_irqrestore(&cctx->lock, flags);
a22465bb4904fac Jeya R 2022-01-26  1548  done:
a22465bb4904fac Jeya R 2022-01-26  1549  	cap->capability = cctx->dsp_attributes[attribute_id];
a22465bb4904fac Jeya R 2022-01-26  1550  
a22465bb4904fac Jeya R 2022-01-26  1551  	return 0;
a22465bb4904fac Jeya R 2022-01-26 @1552  }
a22465bb4904fac Jeya R 2022-01-26  1553  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Dan Carpenter Jan. 28, 2022, 7:09 a.m. UTC | #3
Hi Srinivas,

url:    https://github.com/0day-ci/linux/commits/Srinivas-Kandagatla/misc-fastrpc-Add-missing-DSP-FastRPC-features/20220126-215705
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 515a2f507491e7c3818e74ef4f4e088c1fecb190
config: openrisc-randconfig-m031-20220124 (https://download.01.org/0day-ci/archive/20220127/202201272146.Ci8W6Th6-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 11.2.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>

New smatch warnings:
drivers/misc/fastrpc.c:1856 fastrpc_req_mem_map() warn: variable dereferenced before check 'map' (see line 1834)

vim +/map +1856 drivers/misc/fastrpc.c

b1c0b7969aa491 Jeya R              2022-01-26  1784  static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp)
b1c0b7969aa491 Jeya R              2022-01-26  1785  {
b1c0b7969aa491 Jeya R              2022-01-26  1786  	struct fastrpc_invoke_args args[4] = { [0 ... 3] = { 0 } };
b1c0b7969aa491 Jeya R              2022-01-26  1787  	struct fastrpc_mem_map_req_msg req_msg = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1788  	struct fastrpc_mmap_rsp_msg rsp_msg = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1789  	struct fastrpc_mem_unmap req_unmap = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1790  	struct fastrpc_phy_page pages = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1791  	struct fastrpc_mem_map req;
b1c0b7969aa491 Jeya R              2022-01-26  1792  	struct device *dev = fl->sctx->dev;
b1c0b7969aa491 Jeya R              2022-01-26  1793  	struct fastrpc_map *map = NULL;
b1c0b7969aa491 Jeya R              2022-01-26  1794  	int err;
b1c0b7969aa491 Jeya R              2022-01-26  1795  	u32 sc;
b1c0b7969aa491 Jeya R              2022-01-26  1796  
b1c0b7969aa491 Jeya R              2022-01-26  1797  	if (copy_from_user(&req, argp, sizeof(req)))
b1c0b7969aa491 Jeya R              2022-01-26  1798  		return -EFAULT;
b1c0b7969aa491 Jeya R              2022-01-26  1799  
b1c0b7969aa491 Jeya R              2022-01-26  1800  	/* create SMMU mapping */
e52e7cb4a5a6f3 Srinivas Kandagatla 2022-01-26  1801  	err = fastrpc_map_create(fl, req.fd, req.length, 0, &map);
b1c0b7969aa491 Jeya R              2022-01-26  1802  	if (err) {
b1c0b7969aa491 Jeya R              2022-01-26  1803  		dev_err(dev, "failed to map buffer, fd = %d\n", req.fd);
b1c0b7969aa491 Jeya R              2022-01-26  1804  		return err;
b1c0b7969aa491 Jeya R              2022-01-26  1805  	}
b1c0b7969aa491 Jeya R              2022-01-26  1806  
b1c0b7969aa491 Jeya R              2022-01-26  1807  	req_msg.pgid = fl->tgid;
b1c0b7969aa491 Jeya R              2022-01-26  1808  	req_msg.fd = req.fd;
b1c0b7969aa491 Jeya R              2022-01-26  1809  	req_msg.offset = req.offset;
b1c0b7969aa491 Jeya R              2022-01-26  1810  	req_msg.vaddrin = req.vaddrin;
b1c0b7969aa491 Jeya R              2022-01-26  1811  	map->va = (void *) req.vaddrin;
b1c0b7969aa491 Jeya R              2022-01-26  1812  	req_msg.flags = req.flags;
b1c0b7969aa491 Jeya R              2022-01-26  1813  	req_msg.num = sizeof(pages);
b1c0b7969aa491 Jeya R              2022-01-26  1814  	req_msg.data_len = 0;
b1c0b7969aa491 Jeya R              2022-01-26  1815  
b1c0b7969aa491 Jeya R              2022-01-26  1816  	args[0].ptr = (u64) &req_msg;
b1c0b7969aa491 Jeya R              2022-01-26  1817  	args[0].length = sizeof(req_msg);
b1c0b7969aa491 Jeya R              2022-01-26  1818  
b1c0b7969aa491 Jeya R              2022-01-26  1819  	pages.addr = map->phys;
b1c0b7969aa491 Jeya R              2022-01-26  1820  	pages.size = map->size;
b1c0b7969aa491 Jeya R              2022-01-26  1821  
b1c0b7969aa491 Jeya R              2022-01-26  1822  	args[1].ptr = (u64) &pages;
b1c0b7969aa491 Jeya R              2022-01-26  1823  	args[1].length = sizeof(pages);
b1c0b7969aa491 Jeya R              2022-01-26  1824  
b1c0b7969aa491 Jeya R              2022-01-26  1825  	args[2].ptr = (u64) &pages;
b1c0b7969aa491 Jeya R              2022-01-26  1826  	args[2].length = 0;
b1c0b7969aa491 Jeya R              2022-01-26  1827  
b1c0b7969aa491 Jeya R              2022-01-26  1828  	args[3].ptr = (u64) &rsp_msg;
b1c0b7969aa491 Jeya R              2022-01-26  1829  	args[3].length = sizeof(rsp_msg);
b1c0b7969aa491 Jeya R              2022-01-26  1830  
b1c0b7969aa491 Jeya R              2022-01-26  1831  	sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_MAP, 3, 1);
b1c0b7969aa491 Jeya R              2022-01-26  1832  	err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]);
b1c0b7969aa491 Jeya R              2022-01-26  1833  	if (err) {
b1c0b7969aa491 Jeya R              2022-01-26 @1834  		dev_err(dev, "mem mmap error, fd %d, vaddr %llx, size %lld\n",
b1c0b7969aa491 Jeya R              2022-01-26  1835  			req.fd, req.vaddrin, map->size);
b1c0b7969aa491 Jeya R              2022-01-26  1836  		goto err_invoke;
b1c0b7969aa491 Jeya R              2022-01-26  1837  	}
b1c0b7969aa491 Jeya R              2022-01-26  1838  
b1c0b7969aa491 Jeya R              2022-01-26  1839  	/* update the buffer to be able to deallocate the memory on the DSP */
b1c0b7969aa491 Jeya R              2022-01-26  1840  	map->raddr = rsp_msg.vaddr;
b1c0b7969aa491 Jeya R              2022-01-26  1841  
b1c0b7969aa491 Jeya R              2022-01-26  1842  	/* let the client know the address to use */
b1c0b7969aa491 Jeya R              2022-01-26  1843  	req.vaddrout = rsp_msg.vaddr;
b1c0b7969aa491 Jeya R              2022-01-26  1844  
b1c0b7969aa491 Jeya R              2022-01-26  1845  	if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
b1c0b7969aa491 Jeya R              2022-01-26  1846  		/* unmap the memory and release the buffer */
b1c0b7969aa491 Jeya R              2022-01-26  1847  		req_unmap.vaddr = (uintptr_t) rsp_msg.vaddr;
b1c0b7969aa491 Jeya R              2022-01-26  1848  		req_unmap.length = map->size;
b1c0b7969aa491 Jeya R              2022-01-26  1849  		fastrpc_req_mem_unmap_impl(fl, &req_unmap);
b1c0b7969aa491 Jeya R              2022-01-26  1850  		return -EFAULT;
b1c0b7969aa491 Jeya R              2022-01-26  1851  	}
b1c0b7969aa491 Jeya R              2022-01-26  1852  
b1c0b7969aa491 Jeya R              2022-01-26  1853  	return 0;
b1c0b7969aa491 Jeya R              2022-01-26  1854  
b1c0b7969aa491 Jeya R              2022-01-26  1855  err_invoke:
b1c0b7969aa491 Jeya R              2022-01-26 @1856  	if (map)
b1c0b7969aa491 Jeya R              2022-01-26  1857  		fastrpc_map_put(map);

"map" can't be NULL.

b1c0b7969aa491 Jeya R              2022-01-26  1858  
b1c0b7969aa491 Jeya R              2022-01-26  1859  	return err;
b1c0b7969aa491 Jeya R              2022-01-26  1860  }

---
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/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 6052a9cb9e2c..56ec7170b698 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -100,9 +100,20 @@  struct fastrpc_invoke_buf {
 	u32 pgidx;		/* index to start of contiguous region */
 };
 
-struct fastrpc_remote_arg {
-	u64 pv;
-	u64 len;
+struct fastrpc_remote_dmahandle {
+	s32 fd;		/* dma handle fd */
+	u32 offset;	/* dma handle offset */
+	u32 len;	/* dma handle length */
+};
+
+struct fastrpc_remote_buf {
+	u64 pv;		/* buffer pointer */
+	u64 len;	/* length of buffer */
+};
+
+union fastrpc_remote_arg {
+	struct fastrpc_remote_buf buf;
+	struct fastrpc_remote_dmahandle dma;
 };
 
 struct fastrpc_mmap_rsp_msg {
@@ -216,7 +227,7 @@  struct fastrpc_invoke_ctx {
 	struct work_struct put_work;
 	struct fastrpc_msg msg;
 	struct fastrpc_user *fl;
-	struct fastrpc_remote_arg *rpra;
+	union fastrpc_remote_arg *rpra;
 	struct fastrpc_map **maps;
 	struct fastrpc_buf *buf;
 	struct fastrpc_invoke_args *args;
@@ -766,7 +777,7 @@  static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
  * >>>>>>  START of METADATA <<<<<<<<<
  * +---------------------------------+
  * |           Arguments             |
- * | type:(struct fastrpc_remote_arg)|
+ * | type:(union fastrpc_remote_arg)|
  * |             (0 - N)             |
  * +---------------------------------+
  * |         Invoke Buffer list      |
@@ -791,7 +802,7 @@  static int fastrpc_get_meta_size(struct fastrpc_invoke_ctx *ctx)
 {
 	int size = 0;
 
-	size = (sizeof(struct fastrpc_remote_arg) +
+	size = (sizeof(struct fastrpc_remote_buf) +
 		sizeof(struct fastrpc_invoke_buf) +
 		sizeof(struct fastrpc_phy_page)) * ctx->nscalars +
 		sizeof(u64) * FASTRPC_MAX_FDLIST +
@@ -856,7 +867,7 @@  static struct fastrpc_phy_page *fastrpc_phy_page_start(struct fastrpc_invoke_buf
 static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 {
 	struct device *dev = ctx->fl->sctx->dev;
-	struct fastrpc_remote_arg *rpra;
+	union fastrpc_remote_arg *rpra;
 	struct fastrpc_invoke_buf *list;
 	struct fastrpc_phy_page *pages;
 	int inbufs, i, oix, err = 0;
@@ -892,8 +903,8 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 		i = ctx->olaps[oix].raix;
 		len = ctx->args[i].length;
 
-		rpra[i].pv = 0;
-		rpra[i].len = len;
+		rpra[i].buf.pv = 0;
+		rpra[i].buf.len = len;
 		list[i].num = len ? 1 : 0;
 		list[i].pgidx = i;
 
@@ -903,7 +914,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 		if (ctx->maps[i]) {
 			struct vm_area_struct *vma = NULL;
 
-			rpra[i].pv = (u64) ctx->args[i].ptr;
+			rpra[i].buf.pv = (u64) ctx->args[i].ptr;
 			pages[i].addr = ctx->maps[i]->phys;
 
 			mmap_read_lock(current->mm);
@@ -930,7 +941,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 			if (rlen < mlen)
 				goto bail;
 
-			rpra[i].pv = args - ctx->olaps[oix].offset;
+			rpra[i].buf.pv = args - ctx->olaps[oix].offset;
 			pages[i].addr = ctx->buf->phys -
 					ctx->olaps[oix].offset +
 					(pkt_size - rlen);
@@ -944,7 +955,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 		}
 
 		if (i < inbufs && !ctx->maps[i]) {
-			void *dst = (void *)(uintptr_t)rpra[i].pv;
+			void *dst = (void *)(uintptr_t)rpra[i].buf.pv;
 			void *src = (void *)(uintptr_t)ctx->args[i].ptr;
 
 			if (!kernel) {
@@ -960,12 +971,15 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 	}
 
 	for (i = ctx->nbufs; i < ctx->nscalars; ++i) {
-		rpra[i].pv = (u64) ctx->args[i].ptr;
-		rpra[i].len = ctx->args[i].length;
 		list[i].num = ctx->args[i].length ? 1 : 0;
 		list[i].pgidx = i;
-		pages[i].addr = ctx->maps[i]->phys;
-		pages[i].size = ctx->maps[i]->size;
+		if (ctx->maps[i]) {
+			pages[i].addr = ctx->maps[i]->phys;
+			pages[i].size = ctx->maps[i]->size;
+		}
+		rpra[i].dma.fd = ctx->args[i].fd;
+		rpra[i].dma.len = ctx->args[i].length;
+		rpra[i].dma.offset = (u64) ctx->args[i].ptr;
 	}
 
 bail:
@@ -978,7 +992,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
 			    u32 kernel)
 {
-	struct fastrpc_remote_arg *rpra = ctx->rpra;
+	union fastrpc_remote_arg *rpra = ctx->rpra;
 	struct fastrpc_user *fl = ctx->fl;
 	struct fastrpc_map *mmap = NULL;
 	struct fastrpc_invoke_buf *list;
@@ -995,9 +1009,9 @@  static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
 
 	for (i = inbufs; i < ctx->nbufs; ++i) {
 		if (!ctx->maps[i]) {
-			void *src = (void *)(uintptr_t)rpra[i].pv;
+			void *src = (void *)(uintptr_t)rpra[i].buf.pv;
 			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
-			u64 len = rpra[i].len;
+			u64 len = rpra[i].buf.len;
 
 			if (!kernel) {
 				if (copy_to_user((void __user *)dst, src, len))