2020-08-20 18:10:55

by Alex Dewar

[permalink] [raw]
Subject: [PATCH] scsi: mptfusion: Remove unnecessarily casts

In a number of places, the value returned from pci_alloc_consistent() is
unnecessarily cast from void*. Remove these casts.

Issue identified with Coccinelle.

Signed-off-by: Alex Dewar <[email protected]>
---
drivers/message/fusion/mptbase.c | 6 +++---
drivers/message/fusion/mptctl.c | 5 ++---
drivers/message/fusion/mptfc.c | 8 ++++----
3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 9903e9660a38..e61f46fbe7f4 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -4975,7 +4975,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)

if (hdr.PageLength > 0) {
data_sz = hdr.PageLength * 4;
- ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
+ ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
rc = -ENOMEM;
if (ppage0_alloc) {
memset((u8 *)ppage0_alloc, 0, data_sz);
@@ -5021,7 +5021,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)

data_sz = hdr.PageLength * 4;
rc = -ENOMEM;
- ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
+ ppage1_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
if (ppage1_alloc) {
memset((u8 *)ppage1_alloc, 0, data_sz);
cfg.physAddr = page1_dma;
@@ -5322,7 +5322,7 @@ GetIoUnitPage2(MPT_ADAPTER *ioc)
/* Read the config page */
data_sz = hdr.PageLength * 4;
rc = -ENOMEM;
- ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
+ ppage_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
if (ppage_alloc) {
memset((u8 *)ppage_alloc, 0, data_sz);
cfg.physAddr = page_dma;
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 1074b882c57c..24aebad60366 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -2593,7 +2593,7 @@ mptctl_hp_targetinfo(MPT_ADAPTER *ioc, unsigned long arg)
/* Get the data transfer speeds
*/
data_sz = ioc->spi_data.sdp0length * 4;
- pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
+ pg0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
if (pg0_alloc) {
hdr.PageVersion = ioc->spi_data.sdp0version;
hdr.PageLength = data_sz;
@@ -2657,8 +2657,7 @@ mptctl_hp_targetinfo(MPT_ADAPTER *ioc, unsigned long arg)
/* Issue the second config page request */
cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
- pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
- ioc->pcidev, data_sz, &page_dma);
+ pg3_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
if (pg3_alloc) {
cfg.physAddr = page_dma;
cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index 4314a3352b96..5abaadc4fc38 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -763,7 +763,7 @@ mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)

data_sz = hdr.PageLength * 4;
rc = -ENOMEM;
- ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
+ ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
if (ppage0_alloc) {

try_again:
@@ -904,9 +904,9 @@ mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum)
if (data_sz < sizeof(FCPortPage1_t))
data_sz = sizeof(FCPortPage1_t);

- page1_alloc = (FCPortPage1_t *) pci_alloc_consistent(ioc->pcidev,
- data_sz,
- &page1_dma);
+ page1_alloc = pci_alloc_consistent(ioc->pcidev,
+ data_sz,
+ &page1_dma);
if (!page1_alloc)
return -ENOMEM;
}
--
2.28.0


2020-08-20 18:58:45

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] scsi: mptfusion: Remove unnecessarily casts

On Thu, 2020-08-20 at 19:05 +0100, Alex Dewar wrote:
> In a number of places, the value returned from pci_alloc_consistent() is
> unnecessarily cast from void*. Remove these casts.
[]
> diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
[]
> @@ -4975,7 +4975,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
>
> if (hdr.PageLength > 0) {
> data_sz = hdr.PageLength * 4;
> - ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
> + ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
> rc = -ENOMEM;
> if (ppage0_alloc) {
> memset((u8 *)ppage0_alloc, 0, data_sz);

If you are removing unnecessary casts, it'd be better to remove
all of them in the same file or subsystem at once.

Also this memset and cast isn't actually necessary any more
as pci_alloc_consistent already zeros memory.

etc...

2020-08-20 18:59:59

by Alex Dewar

[permalink] [raw]
Subject: Re: [PATCH] scsi: mptfusion: Remove unnecessarily casts

On Thu, Aug 20, 2020 at 11:53:58AM -0700, Joe Perches wrote:
> On Thu, 2020-08-20 at 19:05 +0100, Alex Dewar wrote:
> > In a number of places, the value returned from pci_alloc_consistent() is
> > unnecessarily cast from void*. Remove these casts.
> []
> > diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
> []
> > @@ -4975,7 +4975,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
> >
> > if (hdr.PageLength > 0) {
> > data_sz = hdr.PageLength * 4;
> > - ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
> > + ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
> > rc = -ENOMEM;
> > if (ppage0_alloc) {
> > memset((u8 *)ppage0_alloc, 0, data_sz);
>
> If you are removing unnecessary casts, it'd be better to remove
> all of them in the same file or subsystem at once.
>
> Also this memset and cast isn't actually necessary any more
> as pci_alloc_consistent already zeros memory.
>
> etc...
>

Good suggestion. Thanks for the feedback :-)