GenWQE: Adjustments for some function implementations
cover GenWQE: Adjustments for some function implementations
From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 10:32:23 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Delete an error message for a failed memory allocation in genwqe_user_vmap() Fix a typo in two comments
Adjust 12 checks for null pointers
drivers/misc/genwqe/card_utils.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
Signature · 1 line
2.15.1
PATCH 1/3 GenWQE: Delete an error message for a failed memory allocation in genwqe_user_vmap()
From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 09:37:23 +0100
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- drivers/misc/genwqe/card_utils.c | 1 - 1 file changed, 1 deletion(-)
drivers/misc/genwqe/card_utils.c +0 -1
@@ -593,7 +593,6 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,sizeof (struct page *) +sizeof (dma_addr_t), GFP_KERNEL);if (!m->page_list) { -dev_err (&pci_dev->dev,"err: alloc page_list failed\n" ); m->nr_pages =0 ; m->u_vaddr =NULL ; m->size =0 ;/* mark unused and not added */
Signature · 1 line
2.15.1
Re: [PATCH 1/3] GenWQE: Delete an error message for a failed memory allocation in genwqe_user_vmap()
Hi Markus,
Quoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 09:37:23 +0100Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/misc/genwqe/card_utils.c | 1 - 1 file changed, 1 deletion(-)drivers/misc/genwqe/card_utils.c +0
-0
drivers/misc/genwqe/card_utils.c int genwqe_user_vmap(struct genwqe_dev *cd, struct · line 597
Quoted 5 lines
drivers/misc/genwqe/card_utils.c +0
-1@@ -593,7 +593,6 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,sizeof (struct page *) +sizeof (dma_addr_t), GFP_KERNEL);if (!m->page_list) { -dev_err (&pci_dev->dev,"err: alloc page_list failed\n" );
Are there different printouts which cover this? I mean the debug printout is not
appearing all the time, it must be enabled, if I remember correctly. So why do
you suggest to remove it?
Quoted 3 lines
drivers/misc/genwqe/card_utils.c +0
-0m->nr_pages =0 ; m->u_vaddr =NULL ;
m->size= 0; /* mark unused and not added */
Regards
Frank
Re: [PATCH 1/3] GenWQE: Delete an error message for a failed memory allocation in genwqe_user_vmap()
Quoted 15 lines · haver
Hi Markus,
Quoted 12 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 09:37:23 +0100Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/misc/genwqe/card_utils.c | 1 - 1 file changed, 1 deletion(-)
Quoted 15 lines
drivers/misc/genwqe/card_utils.c int genwqe_user_vmap(struct genwqe_dev *cd, struct · line 597
Quoted 11 lines
drivers/misc/genwqe/card_utils.c +0
-1@@ -593,7 +593,6 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,sizeof (struct page *) +sizeof (dma_addr_t), GFP_KERNEL);if (!m->page_list) { -dev_err (&pci_dev->dev,"err: alloc page_list failed\n" );Are there different printouts which cover this? I mean the debug printout is not
appearing all the time, it must be enabled, if I remember correctly.
The kmalloc() error messages are enabled by default. See warn_alloc(). The stack trace from this specific call site is going to be very clear what went wrong.
Quoted 4 lines
So why
do
you suggest to remove it?
It's a checkpatch warning and a small memory savings.
regards,
dan carpenter
haver
Acked-byRe: [PATCH 1/3] GenWQE: Delete an error message for a failed memory allocation in genwqe_user_vmap()
Hi Dan,
Quoted 33 lines · Dan Carpenter
Quoted 15 lines · haver
Hi Markus,
Quoted 12 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 09:37:23 +0100Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/misc/genwqe/card_utils.c | 1 - 1 file changed, 1 deletion(-)Quoted 16 lines
drivers/misc/genwqe/card_utils.c int genwqe_user_vmap(struct genwqe_dev *cd, struct · line 597
Quoted 11 lines
drivers/misc/genwqe/card_utils.c +0
-1@@ -593,7 +593,6 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,sizeof (struct page *) +sizeof (dma_addr_t), GFP_KERNEL);if (!m->page_list) { -dev_err (&pci_dev->dev,"err: alloc page_list failed\n" );Are there different printouts which cover this? I mean the debug printout is
not
appearing all the time, it must be enabled, if I remember correctly.
Quoted 4 lines
The
kmalloc()error messages are enabled by default. Seewarn_alloc(). The stack trace from this specific call site is going to be very clear what went wrong.
So it appears it is ok to be removed. Let's remove the redundant printout as suggested.
Quoted 10 lines
Quoted 5 lines
So why
do
you suggest to remove it?It's a checkpatch warning and a small memory savings.
regards,
dan carpenter
Re: [PATCH 1/3] GenWQE: Delete an error message for a failed memory allocation in genwqe_user_vmap()
In reply to haverQuoted 8 lines
drivers/misc/genwqe/card_utils.c int genwqe_user_vmap(struct genwqe_dev *cd, struct · line 597
Quoted 6 lines
drivers/misc/genwqe/card_utils.c +0
-1@@ -593,7 +593,6 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr, sizeof(struct page *) + sizeof(dma_addr_t), GFP_KERNEL); if (!m->page_list) { - dev_err(&pci_dev->dev, "err: alloc page_list failed\n");Are there different printouts which cover this?
Is this error message redundant?
Quoted 2 lines
I mean the debug printout is not appearing all the time, it must be enabled, if I remember correctly.
Would you like to clarify corresponding configuration possibilities any more?
Quoted 1 line
So why do you suggest to remove it?
Can the Linux allocation failure report be sufficient for this use case already?
Regards,
Markus
haver
Acked-byRe: [PATCH 1/3] GenWQE: Delete an error message for a failed memory allocation in genwqe_user_vmap()
Quoted 22 lines · SF Markus Elfring
Quoted 11 lines
Quoted 9 lines
(quoted diff) +0
-0@@ -593,7 +593,6 @@ int genwqe_user_vmap(struct genwqe_dev *cd,struct
dma_mapping*m, void *uaddr,
sizeof(struct page *)+sizeof(dma_addr_t),
GFP_KERNEL);
if (!m->page_list) {
-dev_err(&pci_dev->dev, "err: alloc page_list failed\n");Are there different printouts which cover this?
Is this error message redundant?
Quoted 2 lines
I mean the debug printout is not appearing all the time, it must be enabled, if I remember correctly.
Would you like to clarify corresponding configuration possibilities any more?
Quoted 7 lines
Quoted 1 line
So why do you suggest to remove it?
Can the Linux allocation failure report be sufficient for this use case already?
Regards,
Markus
According to Dans message in parallel, it should be redundant and I am fine with removing it.
PATCH 2/3 GenWQE: Fix a typo in two comments
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 09:57:10 +0100
Add a missing character in two words of these descriptions.
--- drivers/misc/genwqe/card_utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/genwqe/card_utils.c +2 -2
@@ -453,7 +453,7 @@ int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, s +=8 ;/* continue 8 elements further */ } fixup: -if (j =1 ) {/* combining happend on last entry! */ +if (j =1 ) {/* combining happened on last entry! */ s -=8 ;/* full shift needed on previous sgl block */ j =7 ;/* shift all elements */ }
@@ -471,7 +471,7 @@ int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl,* genwqe_free_sync_sgl() - Free memory for sgl and overlapping pages * * After the DMA transfer has been completed we free the memory for -* the sgl and the cached pages. Data is being transfered from cached +* the sgl and the cached pages. Data is being transferred from cached * pages into user-space buffers. */ int genwqe_free_sync_sgl (struct genwqe_dev *cd,struct genwqe_sgl *sgl)
Signature · 1 line
2.15.1
Re: [PATCH 2/3] GenWQE: Fix a typo in two comments
Hi Markus,
Quoted 34 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 09:57:10 +0100Add a missing character in two words of these descriptions.
Signed-off-by Markus Elfring <[email protected]>--- drivers/misc/genwqe/card_utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/misc/genwqe/card_utils.c +1
-1@@ -453,7 +453,7 @@ int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, s +=8 ;/* continue 8 elements further */ } fixup: -if (j =1 ) {/* combining happend on last entry! */ +if (j =1 ) {/* combining happened on last entry! */ s -=8 ;/* full shift needed on previous sgl block */ j =7 ;/* shift all elements */ drivers/misc/genwqe/card_utils.c +1
-1}@@ -471,7 +471,7 @@ int genwqe_setup_sgl(struct genwqe_dev *cd, structgenwqe_sgl *sgl, * genwqe_free_sync_sgl() - Free memory for sgl and overlapping pages * * After the DMA transfer has been completed we free the memory for -* the sgl and the cached pages. Data is being transfered from cached +* the sgl and the cached pages. Data is being transferred from cached * pages into user-space buffers. */
Quoted 2 lines
int genwqe_free_sync_sgl(struct
genwqe_dev*cd, structgenwqe_sgl
*sgl)
Looks good to me. Thanks.
Frank
PATCH 3/3 GenWQE: Adjust 12 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 10:21:25 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
--- drivers/misc/genwqe/card_utils.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
drivers/misc/genwqe/card_utils.c +13 -16
@@ -58,7 +58,7 @@ int __genwqe_writeq(struct genwqe_dev *cd, u64 byte_offs, u64 val)if (cd->err_inject &GENWQE_INJECT_HARDWARE_FAILURE )return -EIO ; -if (cd->mmio =NULL ) +if (!cd->mmio)return -EIO ;if (pci_channel_offline (pci_dev))
@@ -88,7 +88,7 @@ u64 __genwqe_readq(struct genwqe_dev *cd, u64 byte_offs) (byte_offs = IO_SLC_CFGREG_GFIR))return 0x00000000ffff0000ull ; -if (cd->mmio =NULL ) +if (!cd->mmio)return 0xffffffffffffffffull ;return be64_to_cpu ((__force __be64 )__raw_readq (cd->mmio + byte_offs));
@@ -109,7 +109,7 @@ int __genwqe_writel(struct genwqe_dev *cd, u64 byte_offs, u32 val)if (cd->err_inject &GENWQE_INJECT_HARDWARE_FAILURE )return -EIO ; -if (cd->mmio =NULL ) +if (!cd->mmio)return -EIO ;if (pci_channel_offline (pci_dev))
@@ -131,7 +131,7 @@ u32 __genwqe_readl(struct genwqe_dev *cd, u64 byte_offs)if (cd->err_inject &GENWQE_INJECT_HARDWARE_FAILURE )return 0xffffffff ; -if (cd->mmio =NULL ) +if (!cd->mmio)return 0xffffffff ;return be32_to_cpu ((__force __be32 )__raw_readl (cd->mmio + byte_offs));
@@ -227,7 +227,7 @@ void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size,void __genwqe_free_consistent (struct genwqe_dev *cd,size_t size,void *vaddr,dma_addr_t dma_handle) { -if (vaddr =NULL ) +if (!vaddr)return ;dma_free_coherent (&cd->pci_dev->dev, size, vaddr, dma_handle);
@@ -323,7 +323,7 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, sgl->sgl =__genwqe_alloc_consistent (cd, sgl->sgl_size, &sgl->sgl_dma_addr); -if (sgl->sgl =NULL ) { +if (!sgl->sgl) {dev_err (&pci_dev->dev,"[%s] err: no memory available!\n" , __func__);return -ENOMEM ;
@@ -333,7 +333,7 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl,if ((sgl->fpage_size !=0 ) && (sgl->fpage_size !=PAGE_SIZE )) { sgl->fpage =__genwqe_alloc_consistent (cd,PAGE_SIZE , &sgl->fpage_dma_addr); -if (sgl->fpage =NULL ) +if (!sgl->fpage) goto err_out;/* Sync with user memory */
@@ -346,7 +346,7 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl,if (sgl->lpage_size !=0 ) { sgl->lpage =__genwqe_alloc_consistent (cd,PAGE_SIZE , &sgl->lpage_dma_addr); -if (sgl->lpage =NULL ) +if (!sgl->lpage) goto err_out1;/* Sync with user memory */
@@ -406,15 +406,12 @@ int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl,/* DMA mapping for requested page, offs, size */ size_to_map =min (size,PAGE_SIZE - map_offs); -if ((p =0 ) && (sgl->fpage !=NULL )) { +if (p =0 && sgl->fpage) daddr = sgl->fpage_dma_addr + map_offs; - - }else if ((p = sgl->nr_pages -1 ) && - (sgl->lpage !=NULL )) { +else if ((p = sgl->nr_pages -1 ) && sgl->lpage) daddr = sgl->lpage_dma_addr; - }else { +else daddr = dma_list[p] + map_offs; - } size -= size_to_map; map_offs =0 ;
@@ -538,7 +535,7 @@ static int genwqe_free_user_pages(struct page **page_list,unsigned int i;for (i =0 ; i < nr_pages; i++) { -if (page_list[i] !=NULL ) { +if (page_list[i]) {if (dirty)set_page_dirty_lock (page_list[i]);put_page (page_list[i]);
@@ -577,7 +574,7 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,unsigned long data, offs;struct pci_dev *pci_dev = cd->pci_dev; -if ((uaddr =NULL ) || (size =0 )) { +if (!uaddr || size =0 ) { m->size =0 ;/* mark unused and not added */ return -EINVAL ; }
Signature · 1 line
2.15.1
Re: [PATCH 3/3] GenWQE: Adjust 12 checks for null pointers
Hi Markus,
Quoted 144 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 10:21:25 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitThe script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
Signed-off-by Markus Elfring <[email protected]>--- drivers/misc/genwqe/card_utils.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)drivers/misc/genwqe/card_utils.c +1
-1@@ -58,7 +58,7 @@ int __genwqe_writeq(struct genwqe_dev *cd, u64 byte_offs, u64 val)if (cd->err_inject &GENWQE_INJECT_HARDWARE_FAILURE )return -EIO ; -if (cd->mmio =NULL ) +if (!cd->mmio)return -EIO ;drivers/misc/genwqe/card_utils.c +1
-1if (pci_channel_offline (pci_dev))@@ -88,7 +88,7 @@ u64 __genwqe_readq(struct genwqe_dev *cd, u64 byte_offs) (byte_offs = IO_SLC_CFGREG_GFIR))return 0x00000000ffff0000ull ; -if (cd->mmio =NULL ) +if (!cd->mmio)return 0xffffffffffffffffull ;return be64_to_cpu((__force __be64)__raw_readq(cd->mmio +
byte_offs));drivers/misc/genwqe/card_utils.c +1
-1@@ -109,7 +109,7 @@ int __genwqe_writel(struct genwqe_dev *cd, u64 byte_offs, u32 val)if (cd->err_inject &GENWQE_INJECT_HARDWARE_FAILURE )return -EIO ; -if (cd->mmio =NULL ) +if (!cd->mmio)return -EIO ;drivers/misc/genwqe/card_utils.c +1
-1if (pci_channel_offline (pci_dev))@@ -131,7 +131,7 @@ u32 __genwqe_readl(struct genwqe_dev *cd, u64 byte_offs)if (cd->err_inject &GENWQE_INJECT_HARDWARE_FAILURE )return 0xffffffff ; -if (cd->mmio =NULL ) +if (!cd->mmio)return 0xffffffff ;return be32_to_cpu((__force __be32)__raw_readl(cd->mmio +
byte_offs));drivers/misc/genwqe/card_utils.c +1
-1@@ -227,7 +227,7 @@ void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size, void __genwqe_free_consistent(struct genwqe_dev *cd, size_t size, void *vaddr, dma_addr_t dma_handle) { -if (vaddr =NULL ) +if (!vaddr)return ;drivers/misc/genwqe/card_utils.c +1
-1dma_free_coherent (&cd->pci_dev->dev, size, vaddr, dma_handle);@@ -323,7 +323,7 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd,struct genwqe_sgl *sgl, sgl->sgl = __genwqe_alloc_consistent(cd, sgl->sgl_size, &sgl->sgl_dma_addr); -if (sgl->sgl =NULL ) { +if (!sgl->sgl) {dev_err (&pci_dev->dev,"[%s] err: no memory available!\n" , __func__);drivers/misc/genwqe/card_utils.c +1
-1return -ENOMEM ;@@ -333,7 +333,7 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd,struct genwqe_sgl *sgl, if ((sgl->fpage_size != 0) && (sgl->fpage_size != PAGE_SIZE)) { sgl->fpage = __genwqe_alloc_consistent(cd, PAGE_SIZE, &sgl->fpage_dma_addr); -if (sgl->fpage =NULL ) +if (!sgl->fpage) goto err_out;drivers/misc/genwqe/card_utils.c +1
-1/* Sync with user memory */ @@ -346,7 +346,7 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, if (sgl->lpage_size != 0) { sgl->lpage =__genwqe_alloc_consistent (cd,PAGE_SIZE , &sgl->lpage_dma_addr); -if (sgl->lpage =NULL ) +if (!sgl->lpage) goto err_out1;drivers/misc/genwqe/card_utils.c +3
-6/* Sync with user memory */ @@ -406,15 +406,12 @@ int genwqe_setup_sgl(struct genwqe_dev *cd,struct genwqe_sgl *sgl,/* DMA mapping for requested page, offs, size */ size_to_map =min (size,PAGE_SIZE - map_offs); -if ((p =0 ) && (sgl->fpage !=NULL )) { +if (p =0 && sgl->fpage) daddr = sgl->fpage_dma_addr + map_offs; - - }else if ((p = sgl->nr_pages -1 ) && - (sgl->lpage !=NULL )) { +else if ((p = sgl->nr_pages -1 ) && sgl->lpage) daddr = sgl->lpage_dma_addr; - }else { +else daddr = dma_list[p] + map_offs; - } size -= size_to_map;drivers/misc/genwqe/card_utils.c +1
-1map_offs =0 ;@@ -538,7 +535,7 @@ static int genwqe_free_user_pages(struct page **page_list, unsigned int i;for (i =0 ; i < nr_pages; i++) { -if (page_list[i] !=NULL ) { +if (page_list[i]) {if (dirty)set_page_dirty_lock (page_list[i]);drivers/misc/genwqe/card_utils.c +1
-1put_page (page_list[i]);@@ -577,7 +574,7 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr, unsigned long data, offs;struct pci_dev *pci_dev = cd->pci_dev; -if ((uaddr =NULL ) || (size =0 )) { +if (!uaddr || size =0 ) { m->size =0 ;/* mark unused and not added */ return -EINVAL ;
Quoted 1 line
}
I personally like the explicit compare (ptr != NULL) more than the !ptr notation.
When was the checkpatch.pl script modified to suggest the latter notation?
Is there any advantage other than the shorter notation?
Regards
Frank
Re: [3/3] GenWQE: Adjust 12 checks for null pointers
Quoted 1 line
I personally like the explicit compare (ptr != NULL) more than the !ptr notation.
Coding style aspects can evolve, can't they?
Quoted 1 line
When was the checkpatch.pl script modified to suggest the latter notation?
Would you like to take another look at the software update “checkpatch: add --strict "pointer comparison to NULL" test� from 2014-12-10?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id·5ac618df751b927469ddbca63cf151a62f0f9d
Quoted 1 line
Is there any advantage other than the shorter notation?
* Do you eventually care for an influence on the run time characteristics for the compilation of this software module?
* How do you think about to reduce the dependency on a special preprocessor symbol?
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html