Skip to contentSkip to conversation

dmaengine: acpi: Drop double check for ACPI companion device

PATCH Superseded Andy Shevchenko 2 participants 5 messages Jun 22, 2020 dmaengine

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: acpi: Drop double check for ACPI companion device

acpi_dev_get_resources() does perform the NULL pointer check against ACPI companion device which is given as function parameter. Thus, there is no need to duplicate this check in the caller.

---
 drivers/dma/acpi-dma.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/dma/acpi-dma.c +6 -11
index 8a05db3343d3..4aee511578ad 100644
@@ -358,19 +358,12 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
 {
 	struct acpi_dma_parser_data pdata;
 	struct acpi_dma_spec *dma_spec = &pdata.dma_spec;
+	struct acpi_device *adev = ACPI_COMPANION(dev);
 	struct list_head resource_list;
-	struct acpi_device *adev;
 	struct acpi_dma *adma;
 	struct dma_chan *chan = NULL;
 	int found;
-
-	/* Check if the device was enumerated by ACPI */
-	if (!dev)
-		return ERR_PTR(-ENODEV);
-
-	adev = ACPI_COMPANION(dev);
-	if (!adev)
-		return ERR_PTR(-ENODEV);
+	int ret;
 
 	memset(&pdata, 0, sizeof(pdata));
 	pdata.index = index;
@@ -380,9 +373,11 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
 	dma_spec->slave_id = -1;
 
 	INIT_LIST_HEAD(&resource_list);
-	acpi_dev_get_resources(adev, &resource_list,
-			acpi_dma_parse_fixed_dma, &pdata);
+	ret = acpi_dev_get_resources(adev, &resource_list,
+				     acpi_dma_parse_fixed_dma, &pdata);
 	acpi_dev_free_resource_list(&resource_list);
+	if (ret < 0)
+		return ret;
 
 	if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
 		return ERR_PTR(-ENODEV);
Signature · 1 line
2.27.0
#1 lore raw
I love your patch! Perhaps something to improve:

Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on slave-dma/next]
[also build test WARNING on linus/master v5.8-rc2 next-20200622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/dmaengine-acpi-Drop-double-check-for-ACPI-companion-device/20200622-170946
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma.git next
config: i386-randconfig-s002-20200622 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-dirty
        # save the attached .config to linux build tree
        make W=1 C=1 ARCH=i386 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> drivers/dma/acpi-dma.c:380:24: sparse: sparse: incorrect type in return expression (different base types) @@     expected struct dma_chan * @@     got int [assigned] ret @@
>> drivers/dma/acpi-dma.c:380:24: sparse:     expected struct dma_chan *
>> drivers/dma/acpi-dma.c:380:24: sparse:     got int [assigned] ret

vim +380 drivers/dma/acpi-dma.c

347
348 /**
349 * acpi_dma_request_slave_chan_by_index - Get the DMA slave channel
350 * @dev: struct device to get DMA request from
351 * @index: index of FixedDMA descriptor for @dev
352 *
353 * Return:
354 * Pointer to appropriate dma channel on success or an error pointer.
355 */
356 struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
357 size_t index)
358 {
359 struct acpi_dma_parser_data pdata;
360 struct acpi_dma_spec *dma_spec = &pdata.dma_spec;
361 struct acpi_device *adev = ACPI_COMPANION(dev);
362 struct list_head resource_list;
363 struct acpi_dma *adma;
364 struct dma_chan *chan = NULL;
365 int found;
366 int ret;
367
368 memset(&pdata, 0, sizeof(pdata));
369 pdata.index = index;
370
371 /* Initial values for the request line and channel */
372 dma_spec->chan_id = -1;
373 dma_spec->slave_id = -1;
374
375 INIT_LIST_HEAD(&resource_list);
376 ret = acpi_dev_get_resources(adev, &resource_list,
377 acpi_dma_parse_fixed_dma, &pdata);
378 acpi_dev_free_resource_list(&resource_list);
379 if (ret < 0)

 > 380			return ret;

381
382 if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
383 return ERR_PTR(-ENODEV);
384
385 mutex_lock(&acpi_dma_lock);
386
387 list_for_each_entry(adma, &acpi_dma_list, dma_controllers) {
388 /*
389 * We are not going to call translation function if slave_id
390 * doesn't fall to the request range.
391 */
392 found = acpi_dma_update_dma_spec(adma, dma_spec);
393 if (found < 0)
394 continue;
395 chan = adma->acpi_dma_xlate(dma_spec, adma);
396 /*
397 * Try to get a channel only from the DMA controller that
398 * matches the slave_id. See acpi_dma_update_dma_spec()
399 * description for the details.
400 */
401 if (found > 0 || chan)
402 break;
403 }
404
405 mutex_unlock(&acpi_dma_lock);
406 return chan ? chan : ERR_PTR(-EPROBE_DEFER);
407 }
408 EXPORT_SYMBOL_GPL(acpi_dma_request_slave_chan_by_index);
409

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Andy Shevchenko
I love your patch! Perhaps something to improve:

Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on slave-dma/next]
[also build test WARNING on linus/master v5.8-rc2 next-20200622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/dmaengine-acpi-Drop-double-check-for-ACPI-companion-device/20200622-170946
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma.git next
config: x86_64-randconfig-s022-20200622 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-dirty
        # save the attached .config to linux build tree
        make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

drivers/dma/acpi-dma.c:380:24: sparse: sparse: incorrect type in return expression (different base types) @@ expected struct dma_chan * @@ got int [assigned] ret @@
drivers/dma/acpi-dma.c:380:24: sparse: expected struct dma_chan *
drivers/dma/acpi-dma.c:380:24: sparse: got int [assigned] ret

>> drivers/dma/acpi-dma.c:380:24: sparse: sparse: non size-preserving integer to pointer cast

vim +380 drivers/dma/acpi-dma.c

347
348 /**
349 * acpi_dma_request_slave_chan_by_index - Get the DMA slave channel
350 * @dev: struct device to get DMA request from
351 * @index: index of FixedDMA descriptor for @dev
352 *
353 * Return:
354 * Pointer to appropriate dma channel on success or an error pointer.
355 */
356 struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
357 size_t index)
358 {
359 struct acpi_dma_parser_data pdata;
360 struct acpi_dma_spec *dma_spec = &pdata.dma_spec;
361 struct acpi_device *adev = ACPI_COMPANION(dev);
362 struct list_head resource_list;
363 struct acpi_dma *adma;
364 struct dma_chan *chan = NULL;
365 int found;
366 int ret;
367
368 memset(&pdata, 0, sizeof(pdata));
369 pdata.index = index;
370
371 /* Initial values for the request line and channel */
372 dma_spec->chan_id = -1;
373 dma_spec->slave_id = -1;
374
375 INIT_LIST_HEAD(&resource_list);
376 ret = acpi_dev_get_resources(adev, &resource_list,
377 acpi_dma_parse_fixed_dma, &pdata);
378 acpi_dev_free_resource_list(&resource_list);
379 if (ret < 0)

 > 380			return ret;

381
382 if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
383 return ERR_PTR(-ENODEV);
384
385 mutex_lock(&acpi_dma_lock);
386
387 list_for_each_entry(adma, &acpi_dma_list, dma_controllers) {
388 /*
389 * We are not going to call translation function if slave_id
390 * doesn't fall to the request range.
391 */
392 found = acpi_dma_update_dma_spec(adma, dma_spec);
393 if (found < 0)
394 continue;
395 chan = adma->acpi_dma_xlate(dma_spec, adma);
396 /*
397 * Try to get a channel only from the DMA controller that
398 * matches the slave_id. See acpi_dma_update_dma_spec()
399 * description for the details.
400 */
401 if (found > 0 || chan)
402 break;
403 }
404
405 mutex_unlock(&acpi_dma_lock);
406 return chan ? chan : ERR_PTR(-EPROBE_DEFER);
407 }
408 EXPORT_SYMBOL_GPL(acpi_dma_request_slave_chan_by_index);
409

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw
In reply to Andy Shevchenko
I love your patch! Perhaps something to improve:

Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on slave-dma/next]
[also build test WARNING on linus/master v5.8-rc2 next-20200622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/dmaengine-acpi-Drop-double-check-for-ACPI-companion-device/20200622-170946
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma.git next
config: i386-randconfig-a006-20200622 (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

drivers/dma/acpi-dma.c: In function 'acpi_dma_request_slave_chan_by_index':

>> drivers/dma/acpi-dma.c:380:10: warning: return makes pointer from integer without a cast [-Wint-conversion]

return ret;
^~~

vim +380 drivers/dma/acpi-dma.c

347
348 /**
349 * acpi_dma_request_slave_chan_by_index - Get the DMA slave channel
350 * @dev: struct device to get DMA request from
351 * @index: index of FixedDMA descriptor for @dev
352 *
353 * Return:
354 * Pointer to appropriate dma channel on success or an error pointer.
355 */
356 struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
357 size_t index)
358 {
359 struct acpi_dma_parser_data pdata;
360 struct acpi_dma_spec *dma_spec = &pdata.dma_spec;
361 struct acpi_device *adev = ACPI_COMPANION(dev);
362 struct list_head resource_list;
363 struct acpi_dma *adma;
364 struct dma_chan *chan = NULL;
365 int found;
366 int ret;
367
368 memset(&pdata, 0, sizeof(pdata));
369 pdata.index = index;
370
371 /* Initial values for the request line and channel */
372 dma_spec->chan_id = -1;
373 dma_spec->slave_id = -1;
374
375 INIT_LIST_HEAD(&resource_list);
376 ret = acpi_dev_get_resources(adev, &resource_list,
377 acpi_dma_parse_fixed_dma, &pdata);
378 acpi_dev_free_resource_list(&resource_list);
379 if (ret < 0)

 > 380			return ret;

381
382 if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
383 return ERR_PTR(-ENODEV);
384
385 mutex_lock(&acpi_dma_lock);
386
387 list_for_each_entry(adma, &acpi_dma_list, dma_controllers) {
388 /*
389 * We are not going to call translation function if slave_id
390 * doesn't fall to the request range.
391 */
392 found = acpi_dma_update_dma_spec(adma, dma_spec);
393 if (found < 0)
394 continue;
395 chan = adma->acpi_dma_xlate(dma_spec, adma);
396 /*
397 * Try to get a channel only from the DMA controller that
398 * matches the slave_id. See acpi_dma_update_dma_spec()
399 * description for the details.
400 */
401 if (found > 0 || chan)
402 break;
403 }
404
405 mutex_unlock(&acpi_dma_lock);
406 return chan ? chan : ERR_PTR(-EPROBE_DEFER);
407 }
408 EXPORT_SYMBOL_GPL(acpi_dma_request_slave_chan_by_index);
409

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#4 lore raw
In reply to Andy Shevchenko
I love your patch! Perhaps something to improve:

Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on slave-dma/next]
[also build test WARNING on linus/master v5.8-rc2 next-20200622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/dmaengine-acpi-Drop-double-check-for-ACPI-companion-device/20200622-170946
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma.git next
config: arm64-randconfig-r025-20200622 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 1d4c87335d5236ea1f35937e1014980ba961ae34)

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 arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/dma/acpi-dma.c:380:10: warning: incompatible integer to pointer conversion returning 'int' from a function with result type 'struct dma_chan *' [-Wint-conversion]

return ret;
^~~
1 warning generated.

vim +380 drivers/dma/acpi-dma.c

347
348 /**
349 * acpi_dma_request_slave_chan_by_index - Get the DMA slave channel
350 * @dev: struct device to get DMA request from
351 * @index: index of FixedDMA descriptor for @dev
352 *
353 * Return:
354 * Pointer to appropriate dma channel on success or an error pointer.
355 */
356 struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
357 size_t index)
358 {
359 struct acpi_dma_parser_data pdata;
360 struct acpi_dma_spec *dma_spec = &pdata.dma_spec;
361 struct acpi_device *adev = ACPI_COMPANION(dev);
362 struct list_head resource_list;
363 struct acpi_dma *adma;
364 struct dma_chan *chan = NULL;
365 int found;
366 int ret;
367
368 memset(&pdata, 0, sizeof(pdata));
369 pdata.index = index;
370
371 /* Initial values for the request line and channel */
372 dma_spec->chan_id = -1;
373 dma_spec->slave_id = -1;
374
375 INIT_LIST_HEAD(&resource_list);
376 ret = acpi_dev_get_resources(adev, &resource_list,
377 acpi_dma_parse_fixed_dma, &pdata);
378 acpi_dev_free_resource_list(&resource_list);
379 if (ret < 0)

 > 380			return ret;

381
382 if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
383 return ERR_PTR(-ENODEV);
384
385 mutex_lock(&acpi_dma_lock);
386
387 list_for_each_entry(adma, &acpi_dma_list, dma_controllers) {
388 /*
389 * We are not going to call translation function if slave_id
390 * doesn't fall to the request range.
391 */
392 found = acpi_dma_update_dma_spec(adma, dma_spec);
393 if (found < 0)
394 continue;
395 chan = adma->acpi_dma_xlate(dma_spec, adma);
396 /*
397 * Try to get a channel only from the DMA controller that
398 * matches the slave_id. See acpi_dma_update_dma_spec()
399 * description for the details.
400 */
401 if (found > 0 || chan)
402 break;
403 }
404
405 mutex_unlock(&acpi_dma_lock);
406 return chan ? chan : ERR_PTR(-EPROBE_DEFER);
407 }
408 EXPORT_SYMBOL_GPL(acpi_dma_request_slave_chan_by_index);
409

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org