[PATCH v2] powerpc/mm: Code cleanup for __hash_page_thp

2024-03-01 Thread Kunwu Chan
This part was commented from commit 6d492ecc6489
("powerpc/THP: Add code to handle HPTE faults for hugepages")
in about 11 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code and replace with a comment
explaining what the dead code was trying to say.

Signed-off-by: Kunwu Chan 
Suggested-by: Michael Ellerman 
Suggested-by: Aneesh Kumar K.V 
---
Changes to v2:
- Replace dead code with a comment as Michael Ellerman said in 
https://lore.kernel.org/all/87h6hva4b0.fsf@mail.lhotse/#R
- Improve commit msg
---
 arch/powerpc/mm/book3s64/hash_hugepage.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/hash_hugepage.c 
b/arch/powerpc/mm/book3s64/hash_hugepage.c
index c0fabe6c5a12..15d6f3ea7178 100644
--- a/arch/powerpc/mm/book3s64/hash_hugepage.c
+++ b/arch/powerpc/mm/book3s64/hash_hugepage.c
@@ -59,16 +59,13 @@ int __hash_page_thp(unsigned long ea, unsigned long access, 
unsigned long vsid,
 
rflags = htab_convert_pte_flags(new_pmd, flags);
 
-#if 0
-   if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) {
+   /*
+* THPs are only supported on platforms that can do mixed page size
+* segments (MPSS) and all such platforms have coherent icache. Hence we
+* don't need to do lazy icache flush (hash_page_do_lazy_icache()) on
+* noexecute fault.
+*/
 
-   /*
-* No CPU has hugepages but lacks no execute, so we
-* don't need to worry about that case
-*/
-   rflags = hash_page_do_lazy_icache(rflags, __pte(old_pte), trap);
-   }
-#endif
/*
 * Find the slot index details for this ea, using base page size.
 */
-- 
2.39.2



Re: [PATCH] powerpc/mm: Code cleanup for __hash_page_thp

2024-02-29 Thread Kunwu Chan

Thanks all for the reply.
On 2024/2/29 14:18, Michael Ellerman wrote:

Aneesh Kumar K.V  writes:

Michael Ellerman  writes:

Kunwu Chan  writes:

On 2024/2/26 18:49, Michael Ellerman wrote:

Kunwu Chan  writes:

This part was commented from commit 6d492ecc6489
("powerpc/THP: Add code to handle HPTE faults for hugepages")
in about 11 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.


I agree the code can go. But I'd like it to be replaced with a comment
explaining what the dead code was trying to say.



Thanks, i'll update a new patch with the following comment:
  /*
  * No CPU has hugepages but lacks no execute, so we
  * don't need to worry about cpu no CPU_FTR_COHERENT_ICACHE feature case
  */


Maybe wait until we can get some input from Aneesh. I'm not sure the
code/comment are really up to date.


How about?

modified   arch/powerpc/mm/book3s64/hash_hugepage.c
@@ -58,17 +58,13 @@ int __hash_page_thp(unsigned long ea, unsigned long access, 
unsigned long vsid,
return 0;
  
  	rflags = htab_convert_pte_flags(new_pmd, flags);

+   /*
+* THPs are only supported on platforms that can do mixed page size
+* segments (MPSS) and all such platforms have coherent icache. Hence we
+* don't need to do lazy icache flush (hash_page_do_lazy_icache()) on
+* noexecute fault.
+*/



I'll use this comment in v2 patch.
And add two Suggested-by: label for you.


Yeah thanks that looks good.

It could say "see eg. __hash_page_4K()", but that's probably unnecessary
as it mentions hash_page_do_lazy_icache(), and anyone interested is just
going to grep for that anyway.

cheers

--
Thanks,
  Kunwu



Re: [PATCH] powerpc/mm: Code cleanup for __hash_page_thp

2024-02-27 Thread Kunwu Chan

Thanks for the reply.
On 2024/2/27 14:07, Michael Ellerman wrote:

Kunwu Chan  writes:

Thanks for the reply.

On 2024/2/26 18:49, Michael Ellerman wrote:

Kunwu Chan  writes:

This part was commented from commit 6d492ecc6489
("powerpc/THP: Add code to handle HPTE faults for hugepages")
in about 11 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.


I agree the code can go. But I'd like it to be replaced with a comment
explaining what the dead code was trying to say.



Thanks, i'll update a new patch with the following comment:
  /*
  * No CPU has hugepages but lacks no execute, so we
  * don't need to worry about cpu no CPU_FTR_COHERENT_ICACHE feature case
  */


Maybe wait until we can get some input from Aneesh. I'm not sure the
code/comment are really up to date.

I won't do anything until I get a reply.
I'll wait for the latest msg.



cheers

--
Thanks,
  Kunwu



Re: [PATCH] powerpc/mm: Code cleanup for __hash_page_thp

2024-02-26 Thread Kunwu Chan

Thanks for the reply.

On 2024/2/26 18:49, Michael Ellerman wrote:

Kunwu Chan  writes:

This part was commented from commit 6d492ecc6489
("powerpc/THP: Add code to handle HPTE faults for hugepages")
in about 11 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.


I agree the code can go. But I'd like it to be replaced with a comment
explaining what the dead code was trying to say.

Thanks, i'll update a new patch with the following comment:
/*
* No CPU has hugepages but lacks no execute, so we
* don't need to worry about cpu no CPU_FTR_COHERENT_ICACHE feature case
*/



cheers


diff --git a/arch/powerpc/mm/book3s64/hash_hugepage.c 
b/arch/powerpc/mm/book3s64/hash_hugepage.c
index c0fabe6c5a12..127a3a2c174b 100644
--- a/arch/powerpc/mm/book3s64/hash_hugepage.c
+++ b/arch/powerpc/mm/book3s64/hash_hugepage.c
@@ -59,16 +59,6 @@ int __hash_page_thp(unsigned long ea, unsigned long access, 
unsigned long vsid,
  
  	rflags = htab_convert_pte_flags(new_pmd, flags);
  
-#if 0

-   if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) {
-
-   /*
-* No CPU has hugepages but lacks no execute, so we
-* don't need to worry about that case
-*/
-   rflags = hash_page_do_lazy_icache(rflags, __pte(old_pte), trap);
-   }
-#endif
/*
 * Find the slot index details for this ea, using base page size.
 */
--
2.39.2

--
Thanks,
  Kunwu



Re: [PATCH v2] powerpc/cell: Code cleanup for spufs_mfc_flush

2024-01-26 Thread Kunwu Chan

On 2024/1/26 14:27, Arnd Bergmann wrote:

On Fri, Jan 26, 2024, at 03:12, Kunwu Chan wrote:

This part was commented from commit a33a7d7309d7
("[PATCH] spufs: implement mfc access for PPE-side DMA")
in about 18 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
Suggested-by: Christophe Leroy 


Nobody is actively working on this code, so it clearly won't
be needed in the future.

Acked-by: Arnd Bergmann 

On the other hand there is probably little use in removing
the dead code either. It looks you sent a lot of these
patches with identical changelog texts to remove blocks
of dead code, which does not seem productive to me as
these were clearly all left in the code to document
something.

Yes, I was doing some cleanup of useless code the other day.
The previous patches were submitted to remove some code that had been 
unused for a long time and was ineffective.
I didn't remove the comments in the header file and the 
debugging-related parts. Because these parts may be used later.


Thank you very much for the reminder.I'll pay attention to whether it 
has a document feature later.


   Arnd

--
Thanks,
  Kunwu



[PATCH] powerpc/pseries/pci: Code cleanup

2024-01-25 Thread Kunwu Chan
This part was commented in about 19 years before.
If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/pseries/pci.c | 27 ---
 1 file changed, 27 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/pci.c 
b/arch/powerpc/platforms/pseries/pci.c
index 1772ae3d193d..6dbc73eb2ca2 100644
--- a/arch/powerpc/platforms/pseries/pci.c
+++ b/arch/powerpc/platforms/pseries/pci.c
@@ -18,33 +18,6 @@
 #include 
 #include "pseries.h"
 
-#if 0
-void pcibios_name_device(struct pci_dev *dev)
-{
-   struct device_node *dn;
-
-   /*
-* Add IBM loc code (slot) as a prefix to the device names for service
-*/
-   dn = pci_device_to_OF_node(dev);
-   if (dn) {
-   const char *loc_code = of_get_property(dn, "ibm,loc-code",
-   NULL);
-   if (loc_code) {
-   int loc_len = strlen(loc_code);
-   if (loc_len < sizeof(dev->dev.name)) {
-   memmove(dev->dev.name+loc_len+1, dev->dev.name,
-   sizeof(dev->dev.name)-loc_len-1);
-   memcpy(dev->dev.name, loc_code, loc_len);
-   dev->dev.name[loc_len] = ' ';
-   dev->dev.name[sizeof(dev->dev.name)-1] = '\0';
-   }
-   }
-   }
-}
-DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_name_device);
-#endif
-
 #ifdef CONFIG_PCI_IOV
 #define MAX_VFS_FOR_MAP_PE 256
 struct pe_map_bar_entry {
-- 
2.39.2



[PATCH v2] powerpc/cell: Code cleanup for spufs_mfc_flush

2024-01-25 Thread Kunwu Chan
This part was commented from commit a33a7d7309d7
("[PATCH] spufs: implement mfc access for PPE-side DMA")
in about 18 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
Suggested-by: Christophe Leroy 
---
Changes in v2:
- Remove unnecessary label 'out'
- Add Suggested-by label in commit msg
---
 arch/powerpc/platforms/cell/spufs/file.c | 20 
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/file.c 
b/arch/powerpc/platforms/cell/spufs/file.c
index 02a8158c469d..7f4e0db8eb08 100644
--- a/arch/powerpc/platforms/cell/spufs/file.c
+++ b/arch/powerpc/platforms/cell/spufs/file.c
@@ -1704,23 +1704,11 @@ static int spufs_mfc_flush(struct file *file, 
fl_owner_t id)
 
ret = spu_acquire(ctx);
if (ret)
-   goto out;
-#if 0
-/* this currently hangs */
-   ret = spufs_wait(ctx->mfc_wq,
-ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
-   if (ret)
-   goto out;
-   ret = spufs_wait(ctx->mfc_wq,
-ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
-   if (ret)
-   goto out;
-#else
-   ret = 0;
-#endif
+   return ret;
+
spu_release(ctx);
-out:
-   return ret;
+
+   return 0;
 }
 
 static int spufs_mfc_fsync(struct file *file, loff_t start, loff_t end, int 
datasync)
-- 
2.39.2



Re: [PATCH] powerpc/cell: Code cleanup for spufs_mfc_flush

2024-01-25 Thread Kunwu Chan

On 2024/1/25 18:41, Christophe Leroy wrote:



Le 25/01/2024 à 11:08, Kunwu Chan a écrit :

This part was commented from commit a33a7d7309d7
("[PATCH] spufs: implement mfc access for PPE-side DMA")
in about 18 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
   arch/powerpc/platforms/cell/spufs/file.c | 12 
   1 file changed, 12 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/file.c 
b/arch/powerpc/platforms/cell/spufs/file.c
index 02a8158c469d..d5e1af483601 100644
--- a/arch/powerpc/platforms/cell/spufs/file.c
+++ b/arch/powerpc/platforms/cell/spufs/file.c
@@ -1705,19 +1705,7 @@ static int spufs_mfc_flush(struct file *file, fl_owner_t 
id)
ret = spu_acquire(ctx);
if (ret)
goto out;
-#if 0
-/* this currently hangs */
-   ret = spufs_wait(ctx->mfc_wq,
-ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
-   if (ret)
-   goto out;
-   ret = spufs_wait(ctx->mfc_wq,
-ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
-   if (ret)
-   goto out;
-#else
ret = 0;



Thanks for your reply.

If you arrived here, it means ret is already 0, otherwise you would have
jumped to label out:, so you can also remove that ret = 0 setting.


I'm patronizing the removal of useless code, it's my bad.

And while you are at it, there is no point in a goto to just a return,
just return instead of the goto, and then you can return 0 directly,
something like:

ret = spu_acquire(ctx);
if (ret)
return ret;

spu_release(ctx);

return 0;


That would be a better cleanup.

Thanks for your suggestions,i'll update in v2 and add a 'Suggested-by:'.



-#endif
spu_release(ctx);
   out:
return ret;

--
Thanks,
  Kunwu



Re: [PATCH] powerpc/mm/hash: Code cleanup

2024-01-25 Thread Kunwu Chan

On 2024/1/25 21:47, Aneesh Kumar K.V wrote:

On 1/25/24 3:16 PM, Kunwu Chan wrote:

This part was commented in about 17 years before.
If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
  arch/powerpc/include/asm/book3s/64/mmu-hash.h | 22 ---
  1 file changed, 22 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h 
b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
index 1c4eebbc69c9..d39ec7134a78 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
@@ -731,26 +731,6 @@ struct hash_mm_context {
  #endif /* CONFIG_PPC_SUBPAGE_PROT */
  };
  
-#if 0

-/*
- * The code below is equivalent to this function for arguments
- * < 2^VSID_BITS, which is all this should ever be called
- * with.  However gcc is not clever enough to compute the
- * modulus (2^n-1) without a second multiply.
- */
-#define vsid_scramble(protovsid, size) \
-   protovsid) * VSID_MULTIPLIER_##size) % VSID_MODULUS_##size))
-
-/* simplified form avoiding mod operation */
-#define vsid_scramble(protovsid, size) \
-   ({   \
-   unsigned long x; \
-   x = (protovsid) * VSID_MULTIPLIER_##size;\
-   x = (x >> VSID_BITS_##size) + (x & VSID_MODULUS_##size); \
-   (x + ((x+1) >> VSID_BITS_##size)) & VSID_MODULUS_##size; \
-   })
-
-#else /* 1 */
  static inline unsigned long vsid_scramble(unsigned long protovsid,
  unsigned long vsid_multiplier, int vsid_bits)
  {
@@ -764,8 +744,6 @@ static inline unsigned long vsid_scramble(unsigned long 
protovsid,
return (vsid + ((vsid + 1) >> vsid_bits)) & vsid_modulus;
  }
  
-#endif /* 1 */

-
  /* Returns the segment size indicator for a user address */
  static inline int user_segment_size(unsigned long addr)
  {


That was done to make sure one can follow the actual compiled code better.

Thanks for your explanation. It's my bad.


-aneesh


--
Thanks,
  Kunwu



[PATCH] powerpc/mm/hash: Code cleanup

2024-01-25 Thread Kunwu Chan
This part was commented in about 17 years before.
If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/include/asm/book3s/64/mmu-hash.h | 22 ---
 1 file changed, 22 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h 
b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
index 1c4eebbc69c9..d39ec7134a78 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
@@ -731,26 +731,6 @@ struct hash_mm_context {
 #endif /* CONFIG_PPC_SUBPAGE_PROT */
 };
 
-#if 0
-/*
- * The code below is equivalent to this function for arguments
- * < 2^VSID_BITS, which is all this should ever be called
- * with.  However gcc is not clever enough to compute the
- * modulus (2^n-1) without a second multiply.
- */
-#define vsid_scramble(protovsid, size) \
-   protovsid) * VSID_MULTIPLIER_##size) % VSID_MODULUS_##size))
-
-/* simplified form avoiding mod operation */
-#define vsid_scramble(protovsid, size) \
-   ({   \
-   unsigned long x; \
-   x = (protovsid) * VSID_MULTIPLIER_##size;\
-   x = (x >> VSID_BITS_##size) + (x & VSID_MODULUS_##size); \
-   (x + ((x+1) >> VSID_BITS_##size)) & VSID_MODULUS_##size; \
-   })
-
-#else /* 1 */
 static inline unsigned long vsid_scramble(unsigned long protovsid,
  unsigned long vsid_multiplier, int vsid_bits)
 {
@@ -764,8 +744,6 @@ static inline unsigned long vsid_scramble(unsigned long 
protovsid,
return (vsid + ((vsid + 1) >> vsid_bits)) & vsid_modulus;
 }
 
-#endif /* 1 */
-
 /* Returns the segment size indicator for a user address */
 static inline int user_segment_size(unsigned long addr)
 {
-- 
2.39.2



[PATCH] powerpc/mm: Code cleanup for __hash_page_thp

2024-01-25 Thread Kunwu Chan
This part was commented from commit 6d492ecc6489
("powerpc/THP: Add code to handle HPTE faults for hugepages")
in about 11 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/mm/book3s64/hash_hugepage.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/hash_hugepage.c 
b/arch/powerpc/mm/book3s64/hash_hugepage.c
index c0fabe6c5a12..127a3a2c174b 100644
--- a/arch/powerpc/mm/book3s64/hash_hugepage.c
+++ b/arch/powerpc/mm/book3s64/hash_hugepage.c
@@ -59,16 +59,6 @@ int __hash_page_thp(unsigned long ea, unsigned long access, 
unsigned long vsid,
 
rflags = htab_convert_pte_flags(new_pmd, flags);
 
-#if 0
-   if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) {
-
-   /*
-* No CPU has hugepages but lacks no execute, so we
-* don't need to worry about that case
-*/
-   rflags = hash_page_do_lazy_icache(rflags, __pte(old_pte), trap);
-   }
-#endif
/*
 * Find the slot index details for this ea, using base page size.
 */
-- 
2.39.2



[PATCH] powerpc/cell: Code cleanup for spufs_mfc_flush

2024-01-25 Thread Kunwu Chan
This part was commented from commit a33a7d7309d7
("[PATCH] spufs: implement mfc access for PPE-side DMA")
in about 18 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/cell/spufs/file.c | 12 
 1 file changed, 12 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/file.c 
b/arch/powerpc/platforms/cell/spufs/file.c
index 02a8158c469d..d5e1af483601 100644
--- a/arch/powerpc/platforms/cell/spufs/file.c
+++ b/arch/powerpc/platforms/cell/spufs/file.c
@@ -1705,19 +1705,7 @@ static int spufs_mfc_flush(struct file *file, fl_owner_t 
id)
ret = spu_acquire(ctx);
if (ret)
goto out;
-#if 0
-/* this currently hangs */
-   ret = spufs_wait(ctx->mfc_wq,
-ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
-   if (ret)
-   goto out;
-   ret = spufs_wait(ctx->mfc_wq,
-ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
-   if (ret)
-   goto out;
-#else
ret = 0;
-#endif
spu_release(ctx);
 out:
return ret;
-- 
2.39.2



Re: [PATCH] KVM: PPC: code cleanup for kvmppc_book3s_irqprio_deliver

2024-01-25 Thread Kunwu Chan

On 2024/1/24 21:01, Christophe Leroy wrote:



Le 24/01/2024 à 10:36, Kunwu Chan a écrit :

This part was commented from commit 2f4cf5e42d13 ("Add book3s.c")
in about 14 years before.
If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
   arch/powerpc/kvm/book3s.c | 3 ---
   1 file changed, 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 8acec144120e..c2f50e04eec8 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -360,9 +360,6 @@ static int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu 
*vcpu,
break;
}
   
-#if 0

-   printk(KERN_INFO "Deliver interrupt 0x%x? %x\n", vec, deliver);
-#endif


Please also remove one of the two blank lines.

Thanks for your reply. I've send the v2 patch:
https://lore.kernel.org/all/20240125082637.532826-1-chen...@kylinos.cn/
https://lore.kernel.org/all/20240125083348.533883-1-chen...@kylinos.cn/
   
   	if (deliver)

kvmppc_inject_interrupt(vcpu, vec, 0);

--
Thanks,
  Kunwu



[PATCH v2] KVM: PPC: code cleanup for kvmppc_book3s_irqprio_deliver

2024-01-25 Thread Kunwu Chan
This part was commented from commit 2f4cf5e42d13 ("Add book3s.c")
in about 14 years before.
If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
Change in v2:
- Remove redundant blank line
---
 arch/powerpc/kvm/book3s.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 8acec144120e..be9fbfbf62f7 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -360,10 +360,6 @@ static int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu 
*vcpu,
break;
}
 
-#if 0
-   printk(KERN_INFO "Deliver interrupt 0x%x? %x\n", vec, deliver);
-#endif
-
if (deliver)
kvmppc_inject_interrupt(vcpu, vec, 0);
 
-- 
2.39.2



[PATCH v2] powerpc/iommu: Code cleanup for cell/iommu.c

2024-01-25 Thread Kunwu Chan
This part was commented from commit 165785e5c0be ("[POWERPC] Cell
iommu support") in about 17 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
Change in v2:
- Remove the second blank line
---
 arch/powerpc/platforms/cell/iommu.c | 17 -
 1 file changed, 17 deletions(-)

diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index 1202a69b0a20..4cd9c0de22c2 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -424,23 +424,6 @@ static void __init cell_iommu_setup_hardware(struct 
cbe_iommu *iommu,
cell_iommu_enable_hardware(iommu);
 }
 
-#if 0/* Unused for now */
-static struct iommu_window *find_window(struct cbe_iommu *iommu,
-   unsigned long offset, unsigned long size)
-{
-   struct iommu_window *window;
-
-   /* todo: check for overlapping (but not equal) windows) */
-
-   list_for_each_entry(window, &(iommu->windows), list) {
-   if (window->offset == offset && window->size == size)
-   return window;
-   }
-
-   return NULL;
-}
-#endif
-
 static inline u32 cell_iommu_get_ioid(struct device_node *np)
 {
const u32 *ioid;
-- 
2.39.2



Re: [PATCH] powerpc/iommu: Code cleanup for cell/iommu.c

2024-01-25 Thread Kunwu Chan

On 2024/1/25 14:49, Christophe Leroy wrote:



Le 25/01/2024 à 03:46, Kunwu Chan a écrit :

This part was commented from commit 165785e5c0be ("[POWERPC] Cell
iommu support") in about 17 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
   arch/powerpc/platforms/cell/iommu.c | 16 
   1 file changed, 16 deletions(-)

diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index 1202a69b0a20..afce9e64a443 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -424,22 +424,6 @@ static void __init cell_iommu_setup_hardware(struct 
cbe_iommu *iommu,
cell_iommu_enable_hardware(iommu);
   }
   
-#if 0/* Unused for now */

-static struct iommu_window *find_window(struct cbe_iommu *iommu,
-   unsigned long offset, unsigned long size)
-{
-   struct iommu_window *window;
-
-   /* todo: check for overlapping (but not equal) windows) */
-
-   list_for_each_entry(window, &(iommu->windows), list) {
-   if (window->offset == offset && window->size == size)
-   return window;
-   }
-
-   return NULL;
-}
-#endif


Same as the other one, please remove the second blank line, don't leave
two blank lines between the remaining functions.

Thanks for your reply.

I'll check my patches and update in v2.



   
   static inline u32 cell_iommu_get_ioid(struct device_node *np)

   {

--
Thanks,
  Kunwu



[PATCH] powerpc/iommu: Code cleanup for cell/iommu.c

2024-01-24 Thread Kunwu Chan
This part was commented from commit 165785e5c0be ("[POWERPC] Cell
iommu support") in about 17 years before.

If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/cell/iommu.c | 16 
 1 file changed, 16 deletions(-)

diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index 1202a69b0a20..afce9e64a443 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -424,22 +424,6 @@ static void __init cell_iommu_setup_hardware(struct 
cbe_iommu *iommu,
cell_iommu_enable_hardware(iommu);
 }
 
-#if 0/* Unused for now */
-static struct iommu_window *find_window(struct cbe_iommu *iommu,
-   unsigned long offset, unsigned long size)
-{
-   struct iommu_window *window;
-
-   /* todo: check for overlapping (but not equal) windows) */
-
-   list_for_each_entry(window, &(iommu->windows), list) {
-   if (window->offset == offset && window->size == size)
-   return window;
-   }
-
-   return NULL;
-}
-#endif
 
 static inline u32 cell_iommu_get_ioid(struct device_node *np)
 {
-- 
2.39.2



[PATCH] KVM: PPC: code cleanup for kvmppc_book3s_irqprio_deliver

2024-01-24 Thread Kunwu Chan
This part was commented from commit 2f4cf5e42d13 ("Add book3s.c")
in about 14 years before.
If there are no plans to enable this part code in the future,
we can remove this dead code.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/kvm/book3s.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 8acec144120e..c2f50e04eec8 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -360,9 +360,6 @@ static int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu 
*vcpu,
break;
}
 
-#if 0
-   printk(KERN_INFO "Deliver interrupt 0x%x? %x\n", vec, deliver);
-#endif
 
if (deliver)
kvmppc_inject_interrupt(vcpu, vec, 0);
-- 
2.39.2



[PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs

2024-01-17 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/pasemi/setup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/platforms/pasemi/setup.c 
b/arch/powerpc/platforms/pasemi/setup.c
index 0761d98e5be3..8f98f3b5 100644
--- a/arch/powerpc/platforms/pasemi/setup.c
+++ b/arch/powerpc/platforms/pasemi/setup.c
@@ -165,6 +165,8 @@ static int __init pas_setup_mce_regs(void)
while (dev && reg < MAX_MCE_REGS) {
mce_regs[reg].name = kasprintf(GFP_KERNEL,
"mc%d_mcdebug_errsta", reg);
+   if (!mce_regs[reg].name)
+   return -ENOMEM;
mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
reg++;
-- 
2.39.2



[PATCH] powerpc/83xx: Add a null pointer check to mcu_gpiochip_add

2024-01-15 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Cc: Kunwu Chan 
Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c 
b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
index 4d8fa9ed1a67..d1ae66eaa687 100644
--- a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
+++ b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
@@ -120,6 +120,8 @@ static int mcu_gpiochip_add(struct mcu *mcu)
 
gc->owner = THIS_MODULE;
gc->label = kasprintf(GFP_KERNEL, "%pfw", dev_fwnode(dev));
+   if (!gc->label)
+   return -ENOMEM;
gc->can_sleep = 1;
gc->ngpio = MCU_NUM_GPIO;
gc->base = -1;
-- 
2.39.2



[PATCH v2] cxl: Fix null pointer dereference in cxl_get_fd

2024-01-11 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Uniformly handle resource release in error paths. And when an
error occurs, an error pointer should be returned.

Fixes: bdecf76e319a ("cxl: Fix coredump generation when cxl_get_fd() is used")
Signed-off-by: Kunwu Chan 
Cc: Kunwu Chan 
Suggested-by: Frederic Barrat 
---
v2: Deal with error path
---
 drivers/misc/cxl/api.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index d85c56530863..b49bc3d29fc0 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -389,19 +389,22 @@ struct file *cxl_get_fd(struct cxl_context *ctx, struct 
file_operations *fops,
int *fd)
 {
struct file *file;
-   int rc, flags, fdtmp;
+   int rc = 0, flags, fdtmp;
char *name = NULL;
 
/* only allow one per context */
-   if (ctx->mapping)
-   return ERR_PTR(-EEXIST);
+   if (ctx->mapping) {
+   rc = -EEXIST;
+   goto err;
+   }
 
flags = O_RDWR | O_CLOEXEC;
 
/* This code is similar to anon_inode_getfd() */
rc = get_unused_fd_flags(flags);
if (rc < 0)
-   return ERR_PTR(rc);
+   goto err;
+
fdtmp = rc;
 
/*
@@ -419,6 +422,10 @@ struct file *cxl_get_fd(struct cxl_context *ctx, struct 
file_operations *fops,
fops = (struct file_operations *)_fops;
 
name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
+   if (!name) {
+   rc = -ENOMEM;
+   goto err_fd;
+   }
file = cxl_getfile(name, fops, ctx, flags);
kfree(name);
if (IS_ERR(file))
@@ -430,6 +437,9 @@ struct file *cxl_get_fd(struct cxl_context *ctx, struct 
file_operations *fops,
 
 err_fd:
put_unused_fd(fdtmp);
+err:
+   if (rc < 0)
+   return ERR_PTR(rc);
return NULL;
 }
 EXPORT_SYMBOL_GPL(cxl_get_fd);
-- 
2.39.2



[PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one

2023-12-08 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.
Add a null pointer check, and release 'ent' to avoid memory leaks.

Fixes: bfd2f0d49aef ("powerpc/powernv: Get rid of old scom_controller 
abstraction")
Cc: Kunwu Chan 
Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/powernv/opal-xscom.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c 
b/arch/powerpc/platforms/powernv/opal-xscom.c
index 262cd6fac907..748c2b97fa53 100644
--- a/arch/powerpc/platforms/powernv/opal-xscom.c
+++ b/arch/powerpc/platforms/powernv/opal-xscom.c
@@ -165,6 +165,11 @@ static int scom_debug_init_one(struct dentry *root, struct 
device_node *dn,
ent->chip = chip;
snprintf(ent->name, 16, "%08x", chip);
ent->path.data = (void *)kasprintf(GFP_KERNEL, "%pOF", dn);
+   if (!ent->path.data) {
+   kfree(ent);
+   return -ENOMEM;
+   }
+
ent->path.size = strlen((char *)ent->path.data);
 
dir = debugfs_create_dir(ent->name, root);
-- 
2.39.2



Re: [PATCH] cxl: Fix null pointer dereference in cxl_get_fd

2023-12-05 Thread Kunwu Chan

Hi Fred,
Thanks for your reply.


But there is a question, whether we should return an error code in error 
path so that the caller of the 'cxl_get_fd' can know the specific 
reason. rather than just return NULL.

Such as:
-   int rc, flags, fdtmp;
+   int rc = 0, flags, fdtmp;
char *name = NULL;

/* only allow one per context */
-   if (ctx->mapping)
-   return ERR_PTR(-EEXIST);
+   if (ctx->mapping) {
+   rc = -EEXIST;
+   goto err;
+   }

flags = O_RDWR | O_CLOEXEC;

/* This code is similar to anon_inode_getfd() */
rc = get_unused_fd_flags(flags);
-   if (rc < 0)
-   return ERR_PTR(rc);
+   if (rc < 0) {
+   goto err;
+   }
fdtmp = rc;



name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
+if (!name) {
+   rc = -ENOMEM;
+   goto err_fd;
+}
file = cxl_getfile(name, fops, ctx, flags);
kfree(name);
@@ -434,6 +437,9 @@ struct file *cxl_get_fd(struct cxl_context *ctx, 
struct file_operations *fops,


 err_fd:
put_unused_fd(fdtmp);
+err:
+   if (rc)
+   return ERR_PTR(rc);
return NULL;


Thanks again,
Kunwu

On 2023/12/4 18:43, Frederic Barrat wrote:



On 04/12/2023 03:07, Kunwu Chan wrote:

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: bdecf76e319a ("cxl: Fix coredump generation when cxl_get_fd() 
is used")

Signed-off-by: Kunwu Chan 
---
  drivers/misc/cxl/api.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index d85c56530863..bfd7ccd4d7e1 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -419,6 +419,10 @@ struct file *cxl_get_fd(struct cxl_context *ctx, 
struct file_operations *fops,

  fops = (struct file_operations *)_fops;
  name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
+    if (!name) {
+    put_unused_fd(fdtmp);
+    return ERR_PTR(-ENOMEM);
+    }



That works, but you might as well follow the existing error path:

 name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
 if (!name)
     goto err_fd;

   Fred



  file = cxl_getfile(name, fops, ctx, flags);
  kfree(name);
  if (IS_ERR(file))


[PATCH v3] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add

2023-12-03 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Suggested-by: Christophe Leroy 
Suggested-by: Michael Ellerman 
Signed-off-by: Kunwu Chan 
---
v2: Use "panic" instead of "return"
v3: Merge two "panic" to one
---
 arch/powerpc/mm/init-common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 119ef491f797..d3a7726ecf51 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -126,7 +126,7 @@ void pgtable_cache_add(unsigned int shift)
 * as to leave enough 0 bits in the address to contain it. */
unsigned long minalign = max(MAX_PGTABLE_INDEX_SIZE + 1,
 HUGEPD_SHIFT_MASK + 1);
-   struct kmem_cache *new;
+   struct kmem_cache *new = NULL;
 
/* It would be nice if this was a BUILD_BUG_ON(), but at the
 * moment, gcc doesn't seem to recognize is_power_of_2 as a
@@ -139,7 +139,8 @@ void pgtable_cache_add(unsigned int shift)
 
align = max_t(unsigned long, align, minalign);
name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift);
-   new = kmem_cache_create(name, table_size, align, 0, ctor(shift));
+   if (name)
+   new = kmem_cache_create(name, table_size, align, 0, 
ctor(shift));
if (!new)
panic("Could not allocate pgtable cache for order %d", shift);
 
-- 
2.34.1



Re: [PATCH v2] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add

2023-12-03 Thread Kunwu Chan

Sure,i'll follow your suggestion in v3 patch:
1. set new to NULL
2. add a 'if' judgment before 'kmem_cache_create'

Thanks,
Kunwu

On 2023/12/1 18:17, Michael Ellerman wrote:

avoid two calls to panic


[PATCH] cxl: Fix null pointer dereference in cxl_get_fd

2023-12-03 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: bdecf76e319a ("cxl: Fix coredump generation when cxl_get_fd() is used")
Signed-off-by: Kunwu Chan 
---
 drivers/misc/cxl/api.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index d85c56530863..bfd7ccd4d7e1 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -419,6 +419,10 @@ struct file *cxl_get_fd(struct cxl_context *ctx, struct 
file_operations *fops,
fops = (struct file_operations *)_fops;
 
name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
+   if (!name) {
+   put_unused_fd(fdtmp);
+   return ERR_PTR(-ENOMEM);
+   }
file = cxl_getfile(name, fops, ctx, flags);
kfree(name);
if (IS_ERR(file))
-- 
2.34.1



[PATCH v2] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add

2023-11-30 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Suggested-by: Christophe Leroy 
Suggested-by: Michael Ellerman 
Signed-off-by: Kunwu Chan 
---
v2: Use "panic" instead of "return"
---
 arch/powerpc/mm/init-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 119ef491f797..9788950b33f5 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -139,6 +139,8 @@ void pgtable_cache_add(unsigned int shift)
 
align = max_t(unsigned long, align, minalign);
name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift);
+   if (!name)
+   panic("Failed to allocate memory for order %d", shift);
new = kmem_cache_create(name, table_size, align, 0, ctor(shift));
if (!new)
panic("Could not allocate pgtable cache for order %d", shift);
-- 
2.34.1



Re: [PATCH] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add

2023-11-30 Thread Kunwu Chan

Thanks for your reply.

Ok, I know what you mean, when name is NULL. The process should be 
aborted and the specific reason for the error should be printed, not 
just return.


I will update v2 patch with "panic".

Thanks again,
Kunwu

On 2023/11/28 19:32, Michael Ellerman wrote:

Kunwu Chan  writes:

Hi Christophe,

Thanks for your reply.
It's my bad. According your reply, i read the code in
sysfs_do_create_link_sd.There is a null pointer check indeed.

My intention was to check null pointer after memory allocation.
Whether we can add a comment here for someone like me, the null pointer
check is no need here?


I don't mind there being a NULL check for name.

But the code shouldn't silently return if name can't be allocated.
Notice that if we can't create the cache we *panic*. A failure to
allocate name, which causes us to skip the cache creation, needs to also
panic.

cheers


On 2023/11/24 23:17, Christophe Leroy wrote:



Le 22/11/2023 à 10:00, Kunwu Chan a écrit :

[Vous ne recevez pas souvent de courriers de chen...@kylinos.cn. Découvrez 
pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.


Are you sure this is needed ? Did you check what happens what name is NULL ?

If I followed stuff correctly, I end up in function
sysfs_do_create_link_sd() which already handles the NULL name case which
a big hammer warning.



Signed-off-by: Kunwu Chan 
---
arch/powerpc/mm/init-common.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 119ef491f797..0884fc601c46 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -139,6 +139,8 @@ void pgtable_cache_add(unsigned int shift)

   align = max_t(unsigned long, align, minalign);
   name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift);
+   if (!name)
+   return;
   new = kmem_cache_create(name, table_size, align, 0, ctor(shift));
   if (!new)
   panic("Could not allocate pgtable cache for order %d", 
shift);
--
2.34.1



Re: [PATCH] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add

2023-11-26 Thread Kunwu Chan

Hi Christophe,

Thanks for your reply.
It's my bad. According your reply, i read the code in 
sysfs_do_create_link_sd.There is a null pointer check indeed.


My intention was to check null pointer after memory allocation.
Whether we can add a comment here for someone like me, the null pointer 
check is no need here?


Thanks,
Kunwu

On 2023/11/24 23:17, Christophe Leroy wrote:



Le 22/11/2023 à 10:00, Kunwu Chan a écrit :

[Vous ne recevez pas souvent de courriers de chen...@kylinos.cn. Découvrez 
pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.


Are you sure this is needed ? Did you check what happens what name is NULL ?

If I followed stuff correctly, I end up in function
sysfs_do_create_link_sd() which already handles the NULL name case which
a big hammer warning.



Signed-off-by: Kunwu Chan 
---
   arch/powerpc/mm/init-common.c | 2 ++
   1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 119ef491f797..0884fc601c46 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -139,6 +139,8 @@ void pgtable_cache_add(unsigned int shift)

  align = max_t(unsigned long, align, minalign);
  name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift);
+   if (!name)
+   return;
  new = kmem_cache_create(name, table_size, align, 0, ctor(shift));
  if (!new)
  panic("Could not allocate pgtable cache for order %d", shift);
--
2.34.1



[PATCH] powerpc/powernv: Add a null pointer check in opal_event_init

2023-11-26 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: 2717a33d6074 ("powerpc/opal-irqchip: Use interrupt names if present")
Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/powernv/opal-irqchip.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/opal-irqchip.c 
b/arch/powerpc/platforms/powernv/opal-irqchip.c
index f9a7001dacb7..56a1f7ce78d2 100644
--- a/arch/powerpc/platforms/powernv/opal-irqchip.c
+++ b/arch/powerpc/platforms/powernv/opal-irqchip.c
@@ -275,6 +275,8 @@ int __init opal_event_init(void)
else
name = kasprintf(GFP_KERNEL, "opal");
 
+   if (!name)
+   continue;
/* Install interrupt handler */
rc = request_irq(r->start, opal_interrupt, r->flags & 
IRQD_TRIGGER_MASK,
 name, NULL);
-- 
2.34.1



[PATCH] powerpc/powernv: Fix null pointer dereference in opal_powercap_init

2023-11-26 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: b9ef7b4b867f ("powerpc: Convert to using %pOFn instead of 
device_node.name")
Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/powernv/opal-powercap.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c 
b/arch/powerpc/platforms/powernv/opal-powercap.c
index 7bfe4cbeb35a..ea917266aa17 100644
--- a/arch/powerpc/platforms/powernv/opal-powercap.c
+++ b/arch/powerpc/platforms/powernv/opal-powercap.c
@@ -196,6 +196,12 @@ void __init opal_powercap_init(void)
 
j = 0;
pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
+   if (!pcaps[i].pg.name) {
+   kfree(pcaps[i].pattrs);
+   kfree(pcaps[i].pg.attrs);
+   goto out_pcaps_pattrs;
+   }
+
if (has_min) {
powercap_add_attr(min, "powercap-min",
  [i].pattrs[j]);
-- 
2.34.1



[PATCH] powerpc/imc-pmu: Fix null pointer dereference in update_events_in_group

2023-11-26 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")
Signed-off-by: Kunwu Chan 
---
 arch/powerpc/perf/imc-pmu.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 5d12ca386c1f..8664a7d297ad 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -299,6 +299,8 @@ static int update_events_in_group(struct device_node *node, 
struct imc_pmu *pmu)
attr_group->attrs = attrs;
do {
ev_val_str = kasprintf(GFP_KERNEL, "event=0x%x", 
pmu->events[i].value);
+   if (!ev_val_str)
+   continue;
dev_str = device_str_attr_create(pmu->events[i].name, 
ev_val_str);
if (!dev_str)
continue;
@@ -306,6 +308,8 @@ static int update_events_in_group(struct device_node *node, 
struct imc_pmu *pmu)
attrs[j++] = dev_str;
if (pmu->events[i].scale) {
ev_scale_str = kasprintf(GFP_KERNEL, "%s.scale", 
pmu->events[i].name);
+   if (!ev_scale_str)
+   continue;
dev_str = device_str_attr_create(ev_scale_str, 
pmu->events[i].scale);
if (!dev_str)
continue;
@@ -315,6 +319,8 @@ static int update_events_in_group(struct device_node *node, 
struct imc_pmu *pmu)
 
if (pmu->events[i].unit) {
ev_unit_str = kasprintf(GFP_KERNEL, "%s.unit", 
pmu->events[i].name);
+   if (!ev_unit_str)
+   continue;
dev_str = device_str_attr_create(ev_unit_str, 
pmu->events[i].unit);
if (!dev_str)
continue;
-- 
2.34.1



[PATCH] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add

2023-11-22 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/mm/init-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 119ef491f797..0884fc601c46 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -139,6 +139,8 @@ void pgtable_cache_add(unsigned int shift)
 
align = max_t(unsigned long, align, minalign);
name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift);
+   if (!name)
+   return;
new = kmem_cache_create(name, table_size, align, 0, ctor(shift));
if (!new)
panic("Could not allocate pgtable cache for order %d", shift);
-- 
2.34.1



[PATCH] powerpc/xics: Check return value of kasprintf in icp_native_map_one_cpu

2023-11-21 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/sysdev/xics/icp-native.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/sysdev/xics/icp-native.c 
b/arch/powerpc/sysdev/xics/icp-native.c
index f6ec6dba92dc..700b67476a7d 100644
--- a/arch/powerpc/sysdev/xics/icp-native.c
+++ b/arch/powerpc/sysdev/xics/icp-native.c
@@ -236,6 +236,8 @@ static int __init icp_native_map_one_cpu(int hw_id, 
unsigned long addr,
rname = kasprintf(GFP_KERNEL, "CPU %d [0x%x] Interrupt Presentation",
  cpu, hw_id);
 
+   if (!rname)
+   return -ENOMEM;
if (!request_mem_region(addr, size, rname)) {
pr_warn("icp_native: Could not reserve ICP MMIO for CPU %d, 
interrupt server #0x%x\n",
cpu, hw_id);
-- 
2.34.1



[PATCH v2] treewide: Spelling fix in comment

2023-10-23 Thread Kunwu Chan
reques -> request

Signed-off-by: Kunwu Chan 
---
 drivers/net/ethernet/toshiba/ps3_gelic_wireless.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c 
b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
index dc14a66583ff..44488c153ea2 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
@@ -1217,7 +1217,7 @@ static int gelic_wl_set_encodeext(struct net_device 
*netdev,
key_index = wl->current_key;
 
if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
-   /* reques to change default key index */
+   /* request to change default key index */
pr_debug("%s: request to change default key to %d\n",
 __func__, key_index);
wl->current_key = key_index;
-- 
2.34.1



Re: [PATCH] treewide: Spelling fix in comment

2023-10-23 Thread Kunwu Chan

Hi Geert,
Thank you very much for your advice, I am a rookie, I am not familiar 
with many aspects, and I need to learn more.  I'll modify the patch.


On 2023/10/20 19:07, Geert Uytterhoeven wrote:

Hi Kunwu,

Thanks for your patch!

This is not a treewide change. Hence the oneline-summary should be
something prefixed by "[net-next] ps3_gelic"

On Fri, Oct 20, 2023 at 11:32 AM Kunwu Chan  wrote:

reques -> request

Fixes: 09dde54c6a69 ("PS3: gelic: Add wireless support for PS3")


No need for a Fixes tag for a spelling fix in a comment.


Signed-off-by: Kunwu Chan 


Reviewed-by: Geert Uytterhoeven 


--- a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
@@ -1217,7 +1217,7 @@ static int gelic_wl_set_encodeext(struct net_device 
*netdev,
 key_index = wl->current_key;

 if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
-   /* reques to change default key index */
+   /* request to change default key index */
 pr_debug("%s: request to change default key to %d\n",
  __func__, key_index);
 wl->current_key = key_index;


Gr{oetje,eeting}s,

 Geert



[PATCH] treewide: Spelling fix in comment

2023-10-21 Thread Kunwu Chan
reques -> request

Fixes: 09dde54c6a69 ("PS3: gelic: Add wireless support for PS3")
Signed-off-by: Kunwu Chan 
---
 drivers/net/ethernet/toshiba/ps3_gelic_wireless.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c 
b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
index dc14a66583ff..44488c153ea2 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
@@ -1217,7 +1217,7 @@ static int gelic_wl_set_encodeext(struct net_device 
*netdev,
key_index = wl->current_key;
 
if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
-   /* reques to change default key index */
+   /* request to change default key index */
pr_debug("%s: request to change default key to %d\n",
 __func__, key_index);
wl->current_key = key_index;
-- 
2.34.1