[RESEND PATCH] accel/habanalabs/gaudi2: Use kvfree() for memory allocated with kvcalloc()

2024-08-20 Thread Thorsten Blum
Use kvfree() to fix the following Coccinelle/coccicheck warning reported
by kfree_mismatch.cocci:

  WARNING kvmalloc is used to allocate this memory at line 10398

Reviewed-by: Tomer Tayar 
Signed-off-by: Thorsten Blum 
---
 drivers/accel/habanalabs/gaudi2/gaudi2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c 
b/drivers/accel/habanalabs/gaudi2/gaudi2.c
index a38b88baadf2..5722e4128d3c 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c
@@ -10437,7 +10437,7 @@ static int gaudi2_memset_device_memory(struct hl_device 
*hdev, u64 addr, u64 siz
(u64 *)(lin_dma_pkts_arr), DEBUGFS_WRITE64);
WREG32(sob_addr, 0);
 
-   kfree(lin_dma_pkts_arr);
+   kvfree(lin_dma_pkts_arr);
 
return rc;
 }
-- 
2.46.0



[RESEND PATCH] accel/habanalabs/gaudi2: Use kvfree() for memory allocated with kvcalloc()

2024-07-03 Thread Thorsten Blum
Use kvfree() to fix the following Coccinelle/coccicheck warning reported
by kfree_mismatch.cocci:

WARNING kvmalloc is used to allocate this memory at line 10398

Reviewed-by: Tomer Tayar 
Signed-off-by: Thorsten Blum 
---
 drivers/accel/habanalabs/gaudi2/gaudi2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c 
b/drivers/accel/habanalabs/gaudi2/gaudi2.c
index fa1c4feb9f89..8024047962ec 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c
@@ -10489,7 +10489,7 @@ static int gaudi2_memset_device_memory(struct hl_device 
*hdev, u64 addr, u64 siz
(u64 *)(lin_dma_pkts_arr), DEBUGFS_WRITE64);
WREG32(sob_addr, 0);
 
-   kfree(lin_dma_pkts_arr);
+   kvfree(lin_dma_pkts_arr);
 
return rc;
 }
-- 
2.45.2



[RESEND PATCH] drm: Combine identical if/elif code blocks

2024-07-09 Thread Thorsten Blum
Merge the identical if/elif code blocks and remove the following two
warnings reported by make includecheck:

  asm/ioctl.h is included more than once
  linux/types.h is included more than once

Reverts commit 00c9672606f7 ("drm: Untangle __KERNEL__ guards") because
make headers_install seems to be able to handle this now.

Signed-off-by: Thorsten Blum 
---
 include/uapi/drm/drm.h | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 16122819edfe..315af7b19c97 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -35,13 +35,7 @@
 #ifndef _DRM_H_
 #define _DRM_H_
 
-#if defined(__KERNEL__)
-
-#include 
-#include 
-typedef unsigned int drm_handle_t;
-
-#elif defined(__linux__)
+#if defined(__KERNEL__) || defined(__linux__)
 
 #include 
 #include 
-- 
2.45.2



[PATCH] drm/i915: Explicitly cast divisor to fix Coccinelle warning

2024-07-10 Thread Thorsten Blum
As the comment explains, the if check ensures that the divisor oa_period
is a u32. Explicitly cast oa_period to u32 to remove the following
Coccinelle/coccicheck warning reported by do_div.cocci:

  WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 
instead

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/i915/i915_perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 0b1cd4c7a525..24722e758aaf 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4103,7 +4103,7 @@ static int read_properties_unlocked(struct i915_perf 
*perf,
 */
if (oa_period <= NSEC_PER_SEC) {
u64 tmp = NSEC_PER_SEC;
-   do_div(tmp, oa_period);
+   do_div(tmp, (u32)oa_period);
oa_freq_hz = tmp;
} else
oa_freq_hz = 0;
-- 
2.45.2



Re: [PATCH] drm/i915: Explicitly cast divisor to fix Coccinelle warning

2024-07-10 Thread Thorsten Blum
On 10. Jul 2024, at 13:38, Ville Syrjälä  wrote:
> On Wed, Jul 10, 2024 at 09:46:51AM +0200, Thorsten Blum wrote:
>> As the comment explains, the if check ensures that the divisor oa_period
>> is a u32. Explicitly cast oa_period to u32 to remove the following
>> Coccinelle/coccicheck warning reported by do_div.cocci:
>> 
>>  WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 
>> instead
>> 
>> Signed-off-by: Thorsten Blum 
>> ---
>> drivers/gpu/drm/i915/i915_perf.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/gpu/drm/i915/i915_perf.c 
>> b/drivers/gpu/drm/i915/i915_perf.c
>> index 0b1cd4c7a525..24722e758aaf 100644
>> --- a/drivers/gpu/drm/i915/i915_perf.c
>> +++ b/drivers/gpu/drm/i915/i915_perf.c
>> @@ -4103,7 +4103,7 @@ static int read_properties_unlocked(struct i915_perf 
>> *perf,
>>  */
>> if (oa_period <= NSEC_PER_SEC) {
>> u64 tmp = NSEC_PER_SEC;
>> - do_div(tmp, oa_period);
>> + do_div(tmp, (u32)oa_period);
> 
> Why is this code even using do_div() when it doesn't need the
> remainder?

do_div() is an optimized 64-by-32 division and the compiler should
automatically remove the remainder if it's not used.

[PATCH] drm/tegra: hub: Use fn parameter directly to fix Coccinelle warning

2024-07-10 Thread Thorsten Blum
The function parameter out can be used directly instead of assigning it
to a temporary u64 variable first.

Remove the local variable tmp2 and use the parameter out directly as the
divisor in do_div() to remove the following Coccinelle/coccicheck
warning reported by do_div.cocci:

  WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 
instead

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/tegra/hub.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/tegra/hub.c b/drivers/gpu/drm/tegra/hub.c
index f21e57e8599e..e0c2019a591b 100644
--- a/drivers/gpu/drm/tegra/hub.c
+++ b/drivers/gpu/drm/tegra/hub.c
@@ -521,12 +521,11 @@ static void tegra_shared_plane_atomic_disable(struct 
drm_plane *plane,
 
 static inline u32 compute_phase_incr(fixed20_12 in, unsigned int out)
 {
-   u64 tmp, tmp1, tmp2;
+   u64 tmp, tmp1;
 
tmp = (u64)dfixed_trunc(in);
-   tmp2 = (u64)out;
-   tmp1 = (tmp << NFB) + (tmp2 >> 1);
-   do_div(tmp1, tmp2);
+   tmp1 = (tmp << NFB) + ((u64)out >> 1);
+   do_div(tmp1, out);
 
return lower_32_bits(tmp1);
 }
-- 
2.45.2



[PATCH] drm/xe/oa: Use vma_pages() helper function in xe_oa_mmap()

2024-07-24 Thread Thorsten Blum
Use the vma_pages() helper function and remove the following
Coccinelle/coccicheck warning reported by vma_pages.cocci:

  WARNING: Consider using vma_pages helper on vma

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/xe/xe_oa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index 6d69f751bf78..133292a9d687 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -1244,8 +1244,7 @@ static int xe_oa_mmap(struct file *file, struct 
vm_area_struct *vma)
vm_flags_mod(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_DONTCOPY,
 VM_MAYWRITE | VM_MAYEXEC);
 
-   xe_assert(stream->oa->xe, bo->ttm.ttm->num_pages ==
- (vma->vm_end - vma->vm_start) >> PAGE_SHIFT);
+   xe_assert(stream->oa->xe, bo->ttm.ttm->num_pages == vma_pages(vma));
for (i = 0; i < bo->ttm.ttm->num_pages; i++) {
ret = remap_pfn_range(vma, start, 
page_to_pfn(bo->ttm.ttm->pages[i]),
  PAGE_SIZE, vma->vm_page_prot);
-- 
2.45.2



[PATCH v2] drm/i915: Explicitly cast divisor and use div_u64()

2024-08-02 Thread Thorsten Blum
As the comment explains, the if check ensures that the divisor oa_period
is a u32. Explicitly cast oa_period to u32 to remove the following
Coccinelle/coccicheck warning reported by do_div.cocci:

  WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 
instead

Use the preferred div_u64() function instead of the do_div() macro and
remove the now unnecessary local variable tmp.

Signed-off-by: Thorsten Blum 
---
Changes in v2:
- Use div_u64() instead of do_div() after feedback from Ville Syrjälä
- Link to v1: 
https://lore.kernel.org/linux-kernel/20240710074650.419902-2-thorsten.b...@toblux.com/
---
 drivers/gpu/drm/i915/i915_perf.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 0b1cd4c7a525..f65fbe13ab59 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4096,15 +4096,13 @@ static int read_properties_unlocked(struct i915_perf 
*perf,
oa_period = oa_exponent_to_ns(perf, value);
 
/* This check is primarily to ensure that oa_period <=
-* UINT32_MAX (before passing to do_div which only
+* UINT32_MAX (before passing it to div_u64 which only
 * accepts a u32 denominator), but we can also skip
 * checking anything < 1Hz which implicitly can't be
 * limited via an integer oa_max_sample_rate.
 */
if (oa_period <= NSEC_PER_SEC) {
-   u64 tmp = NSEC_PER_SEC;
-   do_div(tmp, oa_period);
-   oa_freq_hz = tmp;
+   oa_freq_hz = div_u64(NSEC_PER_SEC, 
(u32)oa_period);
} else
oa_freq_hz = 0;
 
-- 
2.45.2



[PATCH v3] drm/i915: Explicitly cast divisor and use div_u64()

2024-08-07 Thread Thorsten Blum
As the comment explains, the if check ensures that the divisor oa_period
is a u32. Explicitly cast oa_period to u32 to remove the following
Coccinelle/coccicheck warning reported by do_div.cocci:

  WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 
instead

Use the preferred div_u64() function instead of the do_div() macro and
remove the now unnecessary local variable tmp.

Inline the if/else and invert the conditional expression.

Reviewed-by: Jonathan Cavitt 
Signed-off-by: Thorsten Blum 
---
Changes in v2:
- Use div_u64() instead of do_div() after feedback from Ville Syrjälä
- Link to v1: 
https://lore.kernel.org/linux-kernel/20240710074650.419902-2-thorsten.b...@toblux.com/

Changes in v3:
- Inline if/else as suggested by Jonathan Cavitt and Andi Shyti
- Link to v2: 
https://lore.kernel.org/linux-kernel/20240802160323.46518-2-thorsten.b...@toblux.com/
---
 drivers/gpu/drm/i915/i915_perf.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 025a79fe5920..6ff905d2b78f 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4063,17 +4063,13 @@ static int read_properties_unlocked(struct i915_perf 
*perf,
oa_period = oa_exponent_to_ns(perf, value);
 
/* This check is primarily to ensure that oa_period <=
-* UINT32_MAX (before passing to do_div which only
+* UINT32_MAX (before passing it to div_u64 which only
 * accepts a u32 denominator), but we can also skip
 * checking anything < 1Hz which implicitly can't be
 * limited via an integer oa_max_sample_rate.
 */
-   if (oa_period <= NSEC_PER_SEC) {
-   u64 tmp = NSEC_PER_SEC;
-   do_div(tmp, oa_period);
-   oa_freq_hz = tmp;
-   } else
-   oa_freq_hz = 0;
+   oa_freq_hz = oa_period > NSEC_PER_SEC ? 0 :
+   div_u64(NSEC_PER_SEC, (u32)oa_period);
 
if (oa_freq_hz > i915_oa_max_sample_rate && 
!perfmon_capable()) {
drm_dbg(&perf->i915->drm,
-- 
2.45.2



[RESEND PATCH] drm/xe/oa: Use vma_pages() helper function in xe_oa_mmap()

2024-08-19 Thread Thorsten Blum
Use the vma_pages() helper function and remove the following
Coccinelle/coccicheck warning reported by vma_pages.cocci:

  WARNING: Consider using vma_pages helper on vma

Reviewed-by: Ashutosh Dixit 
Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/xe/xe_oa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index 6d69f751bf78..133292a9d687 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -1244,8 +1244,7 @@ static int xe_oa_mmap(struct file *file, struct 
vm_area_struct *vma)
vm_flags_mod(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_DONTCOPY,
 VM_MAYWRITE | VM_MAYEXEC);
 
-   xe_assert(stream->oa->xe, bo->ttm.ttm->num_pages ==
- (vma->vm_end - vma->vm_start) >> PAGE_SHIFT);
+   xe_assert(stream->oa->xe, bo->ttm.ttm->num_pages == vma_pages(vma));
for (i = 0; i < bo->ttm.ttm->num_pages; i++) {
ret = remap_pfn_range(vma, start, 
page_to_pfn(bo->ttm.ttm->pages[i]),
  PAGE_SIZE, vma->vm_page_prot);
-- 
2.46.0



[PATCH] drm: Combine identical if/elif code blocks

2024-05-13 Thread Thorsten Blum
Merge the identical if/elif code blocks and remove the following two
warnings reported by make includecheck:

asm/ioctl.h is included more than once
linux/types.h is included more than once

Signed-off-by: Thorsten Blum 
---
 include/uapi/drm/drm.h | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 16122819edfe..315af7b19c97 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -35,13 +35,7 @@
 #ifndef _DRM_H_
 #define _DRM_H_
 
-#if defined(__KERNEL__)
-
-#include 
-#include 
-typedef unsigned int drm_handle_t;
-
-#elif defined(__linux__)
+#if defined(__KERNEL__) || defined(__linux__)
 
 #include 
 #include 
-- 
2.45.0



Re: [PATCH] drm: Combine identical if/elif code blocks

2024-05-15 Thread Thorsten Blum
On 15. May 2024, at 09:43, Luc Ma  wrote:
> On Tue, 14 May 2024 at 19:37, Thorsten Blum  wrote:
>> 
>> Merge the identical if/elif code blocks and remove the following two
>> warnings reported by make includecheck:
>> 
>>asm/ioctl.h is included more than once
>>linux/types.h is included more than once
>> 
>> Signed-off-by: Thorsten Blum 
>> ---
>> include/uapi/drm/drm.h | 8 +---
>> 1 file changed, 1 insertion(+), 7 deletions(-)
>> 
>> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
>> index 16122819edfe..315af7b19c97 100644
>> --- a/include/uapi/drm/drm.h
>> +++ b/include/uapi/drm/drm.h
>> @@ -35,13 +35,7 @@
>> #ifndef _DRM_H_
>> #define _DRM_H_
>> 
>> -#if defined(__KERNEL__)
>> -
>> -#include 
>> -#include 
>> -typedef unsigned int drm_handle_t;
>> -
>> -#elif defined(__linux__)
> 
> I think it is intentionally like that. Please see
> https://patchwork.freedesktop.org/patch/78747/

Thank you for the link.

Does anyone know if the reason for the change from 2016 ("make
headers_install can't handle fancy conditions, ...") is still valid?

Other headers use the same #if directive:

fs/ext4/ext4.h:948:#if defined(__KERNEL__) || defined(__linux__)
include/uapi/sound/asound.h:11:#if defined(__KERNEL__) || defined(__linux__)

And there are many others using similar conditions:

arch/arm/include/uapi/asm/swab.h:27:#if !defined(__KERNEL__) || 
__LINUX_ARM_ARCH__ < 6
arch/sparc/include/uapi/asm/signal.h:92:#if defined(__KERNEL__) || 
defined(__WANT_POSIX1B_SIGNALS__)
arch/sparc/include/uapi/asm/termios.h:8:#if defined(__KERNEL__) || 
defined(__DEFINE_BSD_TERMIOS)
include/uapi/linux/soundcard.h:1040:#if !defined(__KERNEL__) || 
defined(USE_SEQ_MACROS)
include/uapi/linux/stat.h:7:#if defined(__KERNEL__) || !defined(__GLIBC__) || 
(__GLIBC__ < 2)
include/uapi/sound/asound.h:11:#if defined(__KERNEL__) || defined(__linux__)
...

Thanks,
Thorsten

Re: [PATCH] drm: Combine identical if/elif code blocks

2024-05-15 Thread Thorsten Blum
On 15. May 2024, at 11:22, Thorsten Blum  wrote:
> On 15. May 2024, at 09:43, Luc Ma  wrote:
>> On Tue, 14 May 2024 at 19:37, Thorsten Blum  wrote:
>>> 
>>> Merge the identical if/elif code blocks and remove the following two
>>> warnings reported by make includecheck:
>>> 
>>>  asm/ioctl.h is included more than once
>>>  linux/types.h is included more than once
>>> 
>>> Signed-off-by: Thorsten Blum 
>>> ---
>>> include/uapi/drm/drm.h | 8 +---
>>> 1 file changed, 1 insertion(+), 7 deletions(-)
>>> 
>>> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
>>> index 16122819edfe..315af7b19c97 100644
>>> --- a/include/uapi/drm/drm.h
>>> +++ b/include/uapi/drm/drm.h
>>> @@ -35,13 +35,7 @@
>>> #ifndef _DRM_H_
>>> #define _DRM_H_
>>> 
>>> -#if defined(__KERNEL__)
>>> -
>>> -#include 
>>> -#include 
>>> -typedef unsigned int drm_handle_t;
>>> -
>>> -#elif defined(__linux__)
>> 
>> I think it is intentionally like that. Please see
>> https://patchwork.freedesktop.org/patch/78747/
> 
> Thank you for the link.
> 
> Does anyone know if the reason for the change from 2016 ("make
> headers_install can't handle fancy conditions, ...") is still valid?
> 
> Other headers use the same #if directive:
> 
> fs/ext4/ext4.h:948:#if defined(__KERNEL__) || defined(__linux__)
> include/uapi/sound/asound.h:11:#if defined(__KERNEL__) || defined(__linux__)
> 
> And there are many others using similar conditions:
> 
> arch/arm/include/uapi/asm/swab.h:27:#if !defined(__KERNEL__) || 
> __LINUX_ARM_ARCH__ < 6
> arch/sparc/include/uapi/asm/signal.h:92:#if defined(__KERNEL__) || 
> defined(__WANT_POSIX1B_SIGNALS__)
> arch/sparc/include/uapi/asm/termios.h:8:#if defined(__KERNEL__) || 
> defined(__DEFINE_BSD_TERMIOS)
> include/uapi/linux/soundcard.h:1040:#if !defined(__KERNEL__) || 
> defined(USE_SEQ_MACROS)
> include/uapi/linux/stat.h:7:#if defined(__KERNEL__) || !defined(__GLIBC__) || 
> (__GLIBC__ < 2)
> include/uapi/sound/asound.h:11:#if defined(__KERNEL__) || defined(__linux__)
> ...
> 
> Thanks,
> Thorsten

Re-sending this to linux-ker...@vger.kernel.org because the mailing list
somehow got lost in Luc's reply.

[PATCH] accel/habanalabs/gaudi2: Use kvfree() for memory allocated with kvcalloc()

2024-04-02 Thread Thorsten Blum
Fixes the following Coccinelle/coccicheck warning reported by
kfree_mismatch.cocci:

WARNING kvmalloc is used to allocate this memory at line 10398

Signed-off-by: Thorsten Blum 
---
 drivers/accel/habanalabs/gaudi2/gaudi2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c 
b/drivers/accel/habanalabs/gaudi2/gaudi2.c
index fa1c4feb9f89..8024047962ec 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c
@@ -10489,7 +10489,7 @@ static int gaudi2_memset_device_memory(struct hl_device 
*hdev, u64 addr, u64 siz
(u64 *)(lin_dma_pkts_arr), DEBUGFS_WRITE64);
WREG32(sob_addr, 0);
 
-   kfree(lin_dma_pkts_arr);
+   kvfree(lin_dma_pkts_arr);
 
return rc;
 }
-- 
2.44.0



[PATCH] treewide: Fix common grammar mistake "the the"

2024-04-11 Thread Thorsten Blum
Use `find . -type f -exec sed -i 's/\/the/g' {} +` to find all
occurrences of "the the" and replace them with a single "the".

Changes only comments and documentation - no code changes.

Signed-off-by: Thorsten Blum 
---
 Documentation/trace/histogram.rst | 2 +-
 arch/arm/Kconfig  | 4 ++--
 arch/arm/include/asm/unwind.h | 2 +-
 arch/arm64/Kconfig| 2 +-
 arch/arm64/kernel/entry-ftrace.S  | 2 +-
 arch/s390/kernel/perf_cpum_sf.c   | 2 +-
 arch/s390/kernel/sthyi.c  | 2 +-
 drivers/accessibility/speakup/speakup_soft.c  | 2 +-
 drivers/gpu/drm/i915/display/intel_crt.c  | 2 +-
 drivers/gpu/drm/i915/i915_request.c   | 2 +-
 drivers/mailbox/Kconfig   | 2 +-
 drivers/net/wireless/intel/iwlwifi/fw/api/tx.h| 4 ++--
 drivers/net/wireless/intel/iwlwifi/mvm/phy-ctxt.c | 2 +-
 drivers/scsi/bfa/bfa_fcs_rport.c  | 2 +-
 drivers/scsi/fcoe/fcoe_ctlr.c | 2 +-
 drivers/scsi/isci/host.h  | 2 +-
 drivers/scsi/isci/remote_device.h | 2 +-
 drivers/scsi/isci/remote_node_context.h   | 2 +-
 drivers/scsi/isci/task.c  | 2 +-
 fs/afs/flock.c| 2 +-
 fs/ecryptfs/keystore.c| 2 +-
 fs/netfs/direct_read.c| 2 +-
 fs/netfs/direct_write.c   | 2 +-
 fs/overlayfs/super.c  | 2 +-
 include/uapi/asm-generic/fcntl.h  | 2 +-
 io_uring/kbuf.c   | 2 +-
 lib/zstd/common/fse_decompress.c  | 2 +-
 lib/zstd/decompress/zstd_decompress_block.c   | 2 +-
 scripts/coccinelle/misc/badty.cocci   | 2 +-
 tools/perf/Documentation/perf-diff.txt| 2 +-
 30 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/Documentation/trace/histogram.rst 
b/Documentation/trace/histogram.rst
index 3c9b263de9c2..18a419925a08 100644
--- a/Documentation/trace/histogram.rst
+++ b/Documentation/trace/histogram.rst
@@ -840,7 +840,7 @@ Extended error information
 
   The compound key examples used a key and a sum value (hitcount) to
   sort the output, but we can just as easily use two keys instead.
-  Here's an example where we use a compound key composed of the the
+  Here's an example where we use a compound key composed of the
   common_pid and size event fields.  Sorting with pid as the primary
   key and 'size' as the secondary key allows us to display an
   ordered summary of the recvfrom sizes, with counts, received by
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b14aed3a17ab..f46fb69ff247 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1479,7 +1479,7 @@ config ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND
bool "Extend with bootloader kernel arguments"
help
  The command-line arguments provided by the boot loader will be
- appended to the the device tree bootargs property.
+ appended to the device tree bootargs property.
 
 endchoice
 
@@ -1617,7 +1617,7 @@ config DMI
  continue to boot on existing non-UEFI platforms.
 
  NOTE: This does *NOT* enable or encourage the use of DMI quirks,
- i.e., the the practice of identifying the platform via DMI to
+ i.e., the practice of identifying the platform via DMI to
  decide whether certain workarounds for buggy hardware and/or
  firmware need to be enabled. This would require the DMI subsystem
  to be enabled much earlier than we do on ARM, which is non-trivial.
diff --git a/arch/arm/include/asm/unwind.h b/arch/arm/include/asm/unwind.h
index d60b09a5acfc..a75da9a01f91 100644
--- a/arch/arm/include/asm/unwind.h
+++ b/arch/arm/include/asm/unwind.h
@@ -10,7 +10,7 @@
 
 #ifndef __ASSEMBLY__
 
-/* Unwind reason code according the the ARM EABI documents */
+/* Unwind reason code according the ARM EABI documents */
 enum unwind_reason_code {
URC_OK = 0, /* operation completed successfully */
URC_CONTINUE_UNWIND = 8,
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 7b11c98b3e84..285ae4ca0b83 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2253,7 +2253,7 @@ config CMDLINE
default ""
help
  Provide a set of default command-line options at build time by
- entering them here. As a minimum, you should specify the the
+ entering them here. As a minimum, you should specify the
  root device (e.g. root=/dev/nfs).
 
 choice
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index f0c16640ef21..e24e7d8f8b61 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -94,

[PATCH v2] treewide: Fix common grammar mistake "the the"

2024-04-11 Thread Thorsten Blum
Use `find . -type f -exec sed -i 's/\/the/g' {} +` to find all
occurrences of "the the" and replace them with a single "the".

In arch/arm/include/asm/unwind.h replace "the the" with "to the".

Changes only comments and documentation - no code changes.

Signed-off-by: Thorsten Blum 
Reviewed-by: Randy Dunlap 
Reviewed-by: Tyler Hicks 
---
Changes in v2:
- In arch/arm/include/asm/unwind.h: s/the the/to the/ as pointed out by
  Robin Murphy
- Preserve Reviewed-by: tags
---
 Documentation/trace/histogram.rst | 2 +-
 arch/arm/Kconfig  | 4 ++--
 arch/arm/include/asm/unwind.h | 2 +-
 arch/arm64/Kconfig| 2 +-
 arch/arm64/kernel/entry-ftrace.S  | 2 +-
 arch/s390/kernel/perf_cpum_sf.c   | 2 +-
 arch/s390/kernel/sthyi.c  | 2 +-
 drivers/accessibility/speakup/speakup_soft.c  | 2 +-
 drivers/gpu/drm/i915/display/intel_crt.c  | 2 +-
 drivers/gpu/drm/i915/i915_request.c   | 2 +-
 drivers/mailbox/Kconfig   | 2 +-
 drivers/net/wireless/intel/iwlwifi/fw/api/tx.h| 4 ++--
 drivers/net/wireless/intel/iwlwifi/mvm/phy-ctxt.c | 2 +-
 drivers/scsi/bfa/bfa_fcs_rport.c  | 2 +-
 drivers/scsi/fcoe/fcoe_ctlr.c | 2 +-
 drivers/scsi/isci/host.h  | 2 +-
 drivers/scsi/isci/remote_device.h | 2 +-
 drivers/scsi/isci/remote_node_context.h   | 2 +-
 drivers/scsi/isci/task.c  | 2 +-
 fs/afs/flock.c| 2 +-
 fs/ecryptfs/keystore.c| 2 +-
 fs/netfs/direct_read.c| 2 +-
 fs/netfs/direct_write.c   | 2 +-
 fs/overlayfs/super.c  | 2 +-
 include/uapi/asm-generic/fcntl.h  | 2 +-
 io_uring/kbuf.c   | 2 +-
 lib/zstd/common/fse_decompress.c  | 2 +-
 lib/zstd/decompress/zstd_decompress_block.c   | 2 +-
 scripts/coccinelle/misc/badty.cocci   | 2 +-
 tools/perf/Documentation/perf-diff.txt| 2 +-
 30 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/Documentation/trace/histogram.rst 
b/Documentation/trace/histogram.rst
index 3c9b263de9c2..18a419925a08 100644
--- a/Documentation/trace/histogram.rst
+++ b/Documentation/trace/histogram.rst
@@ -840,7 +840,7 @@ Extended error information
 
   The compound key examples used a key and a sum value (hitcount) to
   sort the output, but we can just as easily use two keys instead.
-  Here's an example where we use a compound key composed of the the
+  Here's an example where we use a compound key composed of the
   common_pid and size event fields.  Sorting with pid as the primary
   key and 'size' as the secondary key allows us to display an
   ordered summary of the recvfrom sizes, with counts, received by
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b14aed3a17ab..f46fb69ff247 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1479,7 +1479,7 @@ config ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND
bool "Extend with bootloader kernel arguments"
help
  The command-line arguments provided by the boot loader will be
- appended to the the device tree bootargs property.
+ appended to the device tree bootargs property.
 
 endchoice
 
@@ -1617,7 +1617,7 @@ config DMI
  continue to boot on existing non-UEFI platforms.
 
  NOTE: This does *NOT* enable or encourage the use of DMI quirks,
- i.e., the the practice of identifying the platform via DMI to
+ i.e., the practice of identifying the platform via DMI to
  decide whether certain workarounds for buggy hardware and/or
  firmware need to be enabled. This would require the DMI subsystem
  to be enabled much earlier than we do on ARM, which is non-trivial.
diff --git a/arch/arm/include/asm/unwind.h b/arch/arm/include/asm/unwind.h
index d60b09a5acfc..9e4313a6309c 100644
--- a/arch/arm/include/asm/unwind.h
+++ b/arch/arm/include/asm/unwind.h
@@ -10,7 +10,7 @@
 
 #ifndef __ASSEMBLY__
 
-/* Unwind reason code according the the ARM EABI documents */
+/* Unwind reason code according to the ARM EABI documents */
 enum unwind_reason_code {
URC_OK = 0, /* operation completed successfully */
URC_CONTINUE_UNWIND = 8,
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 7b11c98b3e84..285ae4ca0b83 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2253,7 +2253,7 @@ config CMDLINE
default ""
help
  Provide a set of default command-line options at build time by
- entering them here. As a minimum, you should specify the the
+ entering them here. As a minimum, you 

Re: [PATCH] treewide: Fix common grammar mistake "the the"

2024-04-11 Thread Thorsten Blum
On 11. Apr 2024, at 17:25, Dan Carpenter  wrote:
> 
> It's tricky to know which tree a patch like this would go through.

The patch is based on the mainline tree. Should I have sent it directly to
Linus then?

I'm relatively new here and therefore only sent it to the corresponding mailing
lists.

Thanks,
Thorsten


[PATCH] drm/amdgpu: Add missing space to DRM_WARN() message

2024-04-14 Thread Thorsten Blum
s/,please/, please/

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 7753a2e64d41..3cba0e196ca8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1455,7 +1455,7 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device 
*adev)
 
/* PCI_EXT_CAP_ID_VNDR extended capability is located at 0x100 */
if (!pci_find_ext_capability(adev->pdev, PCI_EXT_CAP_ID_VNDR))
-   DRM_WARN("System can't access extended configuration 
space,please check!!\n");
+   DRM_WARN("System can't access extended configuration space, 
please check!!\n");
 
/* skip if the bios has already enabled large BAR */
if (adev->gmc.real_vram_size &&
-- 
2.39.2



[RESEND PATCH] drm/managed: Simplify if condition

2024-07-01 Thread Thorsten Blum
The if condition !A || A && B can be simplified to !A || B.

Fixes the following Coccinelle/coccicheck warning reported by
excluded_middle.cocci:

WARNING !A || A && B is equivalent to !A || B

Compile-tested only.

Acked-by: Thomas Zimmermann 
Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_managed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c
index 7646f67bda4e..79ce86a5bd67 100644
--- a/drivers/gpu/drm/drm_managed.c
+++ b/drivers/gpu/drm/drm_managed.c
@@ -197,7 +197,7 @@ void drmm_release_action(struct drm_device *dev,
spin_lock_irqsave(&dev->managed.lock, flags);
list_for_each_entry_reverse(dr, &dev->managed.resources, node.entry) {
if (dr->node.release == action) {
-   if (!data || (data && *(void **)dr->data == data)) {
+   if (!data || *(void **)dr->data == data) {
dr_match = dr;
del_dr(dev, dr_match);
break;
-- 
2.39.2



[RESEND PATCH] accel/habanalabs/gaudi2: Use kvfree() for memory allocated with kvcalloc()

2024-05-31 Thread Thorsten Blum
Use kvfree() to fix the following Coccinelle/coccicheck warning reported
by kfree_mismatch.cocci:

WARNING kvmalloc is used to allocate this memory at line 10398

Signed-off-by: Thorsten Blum 
---
 drivers/accel/habanalabs/gaudi2/gaudi2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c 
b/drivers/accel/habanalabs/gaudi2/gaudi2.c
index fa1c4feb9f89..8024047962ec 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c
@@ -10489,7 +10489,7 @@ static int gaudi2_memset_device_memory(struct hl_device 
*hdev, u64 addr, u64 siz
(u64 *)(lin_dma_pkts_arr), DEBUGFS_WRITE64);
WREG32(sob_addr, 0);
 
-   kfree(lin_dma_pkts_arr);
+   kvfree(lin_dma_pkts_arr);
 
return rc;
 }
-- 
2.45.1



[PATCH] drm/xe/vm: Simplify if condition

2024-06-03 Thread Thorsten Blum
The if condition !A || A && B can be simplified to !A || B.

Fixes the following Coccinelle/coccicheck warning reported by
excluded_middle.cocci:

WARNING !A || A && B is equivalent to !A || B

Compile-tested only.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/xe/xe_vm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 4aa3943e6f29..3137cbbaabde 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -85,8 +85,8 @@ static bool preempt_fences_waiting(struct xe_vm *vm)
 
list_for_each_entry(q, &vm->preempt.exec_queues, compute.link) {
if (!q->compute.pfence ||
-   (q->compute.pfence && 
test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
-  &q->compute.pfence->flags))) 
{
+   test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
+&q->compute.pfence->flags)) {
return true;
}
}
-- 
2.39.2



Re: [PATCH] drm: Combine identical if/elif code blocks

2024-06-03 Thread Thorsten Blum
On 16. May 2024, at 03:24, Luc Ma  wrote:
> On Wed, 15 May 2024 at 17:31, Thorsten Blum  wrote:
>> On 15. May 2024, at 11:22, Thorsten Blum  wrote:
>>> On 15. May 2024, at 09:43, Luc Ma  wrote:
>>>> On Tue, 14 May 2024 at 19:37, Thorsten Blum  
>>>> wrote:
>>>>> 
>>>>> Merge the identical if/elif code blocks and remove the following two
>>>>> warnings reported by make includecheck:
>>>>> 
>>>>> asm/ioctl.h is included more than once
>>>>> linux/types.h is included more than once
>>>>> 
>>>>> Signed-off-by: Thorsten Blum 
>>>>> ---
>>>>> include/uapi/drm/drm.h | 8 +---
>>>>> 1 file changed, 1 insertion(+), 7 deletions(-)
>>>>> 
>>>>> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
>>>>> index 16122819edfe..315af7b19c97 100644
>>>>> --- a/include/uapi/drm/drm.h
>>>>> +++ b/include/uapi/drm/drm.h
>>>>> @@ -35,13 +35,7 @@
>>>>> #ifndef _DRM_H_
>>>>> #define _DRM_H_
>>>>> 
>>>>> -#if defined(__KERNEL__)
>>>>> -
>>>>> -#include 
>>>>> -#include 
>>>>> -typedef unsigned int drm_handle_t;
>>>>> -
>>>>> -#elif defined(__linux__)
>>>> 
>>>> I think it is intentionally like that. Please see
>>>> https://patchwork.freedesktop.org/patch/78747/
>>> 
>>> Thank you for the link.
>>> 
>>> Does anyone know if the reason for the change from 2016 ("make
>>> headers_install can't handle fancy conditions, ...") is still valid?
> 
> I guess it is. If you can try ./scripts/unifdef as below[1], you might
> find out the thing.
> 
> [1]https://elixir.bootlin.com/linux/v6.9/source/scripts/headers_install.sh#L41

I just tested it with make headers_install and it worked fine.

Thorsten

[RESEND PATCH] drm: Combine identical if/elif code blocks

2024-06-04 Thread Thorsten Blum
Merge the identical if/elif code blocks and remove the following two
warnings reported by make includecheck:

asm/ioctl.h is included more than once
linux/types.h is included more than once

Reverts commit 00c9672606f7 ("drm: Untangle __KERNEL__ guards") because
make headers_install seems to be able to handle this now.

Signed-off-by: Thorsten Blum 
---
 include/uapi/drm/drm.h | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 16122819edfe..315af7b19c97 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -35,13 +35,7 @@
 #ifndef _DRM_H_
 #define _DRM_H_
 
-#if defined(__KERNEL__)
-
-#include 
-#include 
-typedef unsigned int drm_handle_t;
-
-#elif defined(__linux__)
+#if defined(__KERNEL__) || defined(__linux__)
 
 #include 
 #include 
-- 
2.39.2



[PATCH] drm/amd/display: Simplify if conditions

2024-06-04 Thread Thorsten Blum
The if conditions !A || A && B can be simplified to !A || B.

Fixes the following Coccinelle/coccicheck warnings reported by
excluded_middle.cocci:

WARNING !A || A && B is equivalent to !A || B
WARNING !A || A && B is equivalent to !A || B
WARNING !A || A && B is equivalent to !A || B

Compile-tested only.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/amd/display/dc/dml2/dml2_dc_resource_mgmt.c | 6 +++---
 .../gpu/drm/amd/display/dc/dml2/dml2_translation_helper.c   | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml2/dml2_dc_resource_mgmt.c 
b/drivers/gpu/drm/amd/display/dc/dml2/dml2_dc_resource_mgmt.c
index ad2a6b4769fe..940081df6dc0 100644
--- a/drivers/gpu/drm/amd/display/dc/dml2/dml2_dc_resource_mgmt.c
+++ b/drivers/gpu/drm/amd/display/dc/dml2/dml2_dc_resource_mgmt.c
@@ -68,7 +68,7 @@ static bool get_plane_id(struct dml2_context *dml2, const 
struct dc_state *state
if (state->streams[i]->stream_id == stream_id) {
for (j = 0; j < state->stream_status[i].plane_count; 
j++) {
if (state->stream_status[i].plane_states[j] == 
plane &&
-   (!is_plane_duplicate || 
(is_plane_duplicate && (j == plane_index {
+   (!is_plane_duplicate || (j == 
plane_index))) {
*plane_id = (i << 16) | j;
return true;
}
@@ -707,8 +707,8 @@ static void free_unused_pipes_for_plane(struct dml2_context 
*ctx, struct dc_stat
for (i = 0; i < ctx->config.dcn_pipe_count; i++) {
if (state->res_ctx.pipe_ctx[i].plane_state == plane &&
state->res_ctx.pipe_ctx[i].stream->stream_id == 
stream_id &&
-   (!is_plane_duplicate || (is_plane_duplicate &&
-   
ctx->v20.scratch.dml_to_dc_pipe_mapping.dml_pipe_idx_to_plane_index[state->res_ctx.pipe_ctx[i].pipe_idx]
 == plane_index)) &&
+   (!is_plane_duplicate ||
+   
ctx->v20.scratch.dml_to_dc_pipe_mapping.dml_pipe_idx_to_plane_index[state->res_ctx.pipe_ctx[i].pipe_idx]
 == plane_index) &&
!is_pipe_used(pool, 
state->res_ctx.pipe_ctx[i].pipe_idx)) {
free_pipe(&state->res_ctx.pipe_ctx[i]);
}
diff --git a/drivers/gpu/drm/amd/display/dc/dml2/dml2_translation_helper.c 
b/drivers/gpu/drm/amd/display/dc/dml2/dml2_translation_helper.c
index a41812598ce8..b2bbf7988f92 100644
--- a/drivers/gpu/drm/amd/display/dc/dml2/dml2_translation_helper.c
+++ b/drivers/gpu/drm/amd/display/dc/dml2/dml2_translation_helper.c
@@ -979,7 +979,7 @@ static bool get_plane_id(struct dml2_context *dml2, const 
struct dc_state *conte
if (context->streams[i]->stream_id == stream_id) {
for (j = 0; j < context->stream_status[i].plane_count; 
j++) {
if (context->stream_status[i].plane_states[j] 
== plane &&
-   (!is_plane_duplicate || 
(is_plane_duplicate && (j == plane_index {
+   (!is_plane_duplicate || (j == 
plane_index))) {
*plane_id = (i << 16) | j;
return true;
}
-- 
2.39.2



[PATCH] drm/managed: Simplify if condition

2024-06-05 Thread Thorsten Blum
The if condition !A || A && B can be simplified to !A || B.

Fixes the following Coccinelle/coccicheck warning reported by
excluded_middle.cocci:

WARNING !A || A && B is equivalent to !A || B

Compile-tested only.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_managed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c
index 7646f67bda4e..79ce86a5bd67 100644
--- a/drivers/gpu/drm/drm_managed.c
+++ b/drivers/gpu/drm/drm_managed.c
@@ -197,7 +197,7 @@ void drmm_release_action(struct drm_device *dev,
spin_lock_irqsave(&dev->managed.lock, flags);
list_for_each_entry_reverse(dr, &dev->managed.resources, node.entry) {
if (dr->node.release == action) {
-   if (!data || (data && *(void **)dr->data == data)) {
+   if (!data || *(void **)dr->data == data) {
dr_match = dr;
del_dr(dev, dr_match);
break;
-- 
2.39.2



[PATCH] drm/amd/display: Fix dml_print_mode_support() for USRRetrainingSupport

2024-06-06 Thread Thorsten Blum
The address of a struct field is usually not NULL, making this test
always truthy. Test the boolean value instead.

Fixes the following Coccinelle/coccicheck error reported by
test_addr.cocci:

ERROR: test of a variable/field address

Compile-tested only.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/amd/display/dc/dml2/display_mode_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml2/display_mode_util.c 
b/drivers/gpu/drm/amd/display/dc/dml2/display_mode_util.c
index c247aee89caf..a98ec059725a 100644
--- a/drivers/gpu/drm/amd/display/dc/dml2/display_mode_util.c
+++ b/drivers/gpu/drm/amd/display/dc/dml2/display_mode_util.c
@@ -404,7 +404,7 @@ void dml_print_mode_support(struct display_mode_lib_st 
*mode_lib, dml_uint_t j)
dml_print("DML: MODE SUPPORT: Host VM or Immediate Flip Supported   
 : %s\n", ((mode_lib->ms.cache_display_cfg.plane.HostVMEnable == false && 
!mode_lib->scratch.dml_core_mode_support_locals.ImmediateFlipRequiredFinal) || 
mode_lib->ms.support.ImmediateFlipSupportedForState[j]) ? "Supported" : "NOT 
Supported");
dml_print("DML: MODE SUPPORT: dram clock change support 
 : %s\n", 
mode_lib->scratch.dml_core_mode_support_locals.dram_clock_change_support == 
true ? "Supported" : "NOT Supported");
dml_print("DML: MODE SUPPORT: f_clock change support
 : %s\n", 
mode_lib->scratch.dml_core_mode_support_locals.f_clock_change_support == true ? 
"Supported" : "NOT Supported");
-   dml_print("DML: MODE SUPPORT: USR Retraining Support
 : %s\n", (!mode_lib->ms.policy.USRRetrainingRequiredFinal || 
&mode_lib->ms.support.USRRetrainingSupport[j]) ? "Supported" : "NOT Supported");
+   dml_print("DML: MODE SUPPORT: USR Retraining Support
 : %s\n", (!mode_lib->ms.policy.USRRetrainingRequiredFinal || 
mode_lib->ms.support.USRRetrainingSupport[j]) ? "Supported" : "NOT Supported");
dml_print("DML: MODE SUPPORT: 
===\n");
 }
 
-- 
2.39.2



[RESEND PATCH] drm/vmwgfx: Remove unnecessary NULL checks before kvfree()

2024-10-07 Thread Thorsten Blum
Since kvfree() already checks if its argument is NULL, an additional
check before calling kvfree() is unnecessary and can be removed.

Remove both and the following Coccinelle/coccicheck warnings reported by
ifnullfree.cocci:

  WARNING: NULL check before some freeing functions is not needed
  WARNING: NULL check before some freeing functions is not needed

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
index 890a66a2361f..64bd7d74854e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
@@ -635,10 +635,8 @@ int vmw_bo_cpu_blit(struct vmw_bo *vmw_dst,
kunmap_atomic(d.src_addr);
if (d.dst_addr)
kunmap_atomic(d.dst_addr);
-   if (src_pages)
-   kvfree(src_pages);
-   if (dst_pages)
-   kvfree(dst_pages);
+   kvfree(src_pages);
+   kvfree(dst_pages);
 
return ret;
 }
-- 
2.46.2



[PATCH] drm/vmwgfx: Remove unnecessary NULL checks before kvfree()

2024-09-23 Thread Thorsten Blum
Since kvfree() already checks if its argument is NULL, an additional
check before calling kvfree() is unnecessary and can be removed.

Remove both and the following Coccinelle/coccicheck warnings reported by
ifnullfree.cocci:

  WARNING: NULL check before some freeing functions is not needed
  WARNING: NULL check before some freeing functions is not needed

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
index 890a66a2361f..64bd7d74854e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
@@ -635,10 +635,8 @@ int vmw_bo_cpu_blit(struct vmw_bo *vmw_dst,
kunmap_atomic(d.src_addr);
if (d.dst_addr)
kunmap_atomic(d.dst_addr);
-   if (src_pages)
-   kvfree(src_pages);
-   if (dst_pages)
-   kvfree(dst_pages);
+   kvfree(src_pages);
+   kvfree(dst_pages);
 
return ret;
 }
-- 
2.46.1



[PATCH] drm/i915: Use memdup_user() instead of kmalloc() and copy_from_user()

2024-09-25 Thread Thorsten Blum
Use memdup_user() instead of kmalloc() followed by copy_from_user() to
simplify set_context_image().

Fixes the following Coccinelle/coccicheck warning reported by
memdup_user.cocci:

  WARNING opportunity for memdup_user

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c 
b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index c0543c35cd6a..c1cc41e90502 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -2159,18 +2159,12 @@ static int set_context_image(struct i915_gem_context 
*ctx,
goto out_ce;
}
 
-   state = kmalloc(ce->engine->context_size, GFP_KERNEL);
-   if (!state) {
-   ret = -ENOMEM;
+   state = memdup_user(u64_to_user_ptr(user.image), 
ce->engine->context_size);
+   if (IS_ERR(state)) {
+   ret = PTR_ERR(state);
goto out_ce;
}
 
-   if (copy_from_user(state, u64_to_user_ptr(user.image),
-  ce->engine->context_size)) {
-   ret = -EFAULT;
-   goto out_state;
-   }
-
shmem_state = shmem_create_from_data(ce->engine->name,
 state, ce->engine->context_size);
if (IS_ERR(shmem_state)) {
-- 
2.46.1



[PATCH] fbdev: Use str_enabled_disabled() helper in sm501fb_init_fb()

2025-01-12 Thread Thorsten Blum
Remove hard-coded strings by using the str_enabled_disabled() helper
function.

Signed-off-by: Thorsten Blum 
---
 drivers/video/fbdev/sm501fb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/sm501fb.c b/drivers/video/fbdev/sm501fb.c
index 86ecbb2d86db..7734377b2d87 100644
--- a/drivers/video/fbdev/sm501fb.c
+++ b/drivers/video/fbdev/sm501fb.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1712,8 +1713,8 @@ static int sm501fb_init_fb(struct fb_info *fb, enum 
sm501_controller head,
BUG();
}
 
-   dev_info(info->dev, "fb %s %sabled at start\n",
-fbname, enable ? "en" : "dis");
+   dev_info(info->dev, "fb %s %s at start\n",
+fbname, str_enabled_disabled(enable));
 
/* check to see if our routing allows this */
 
-- 
2.47.1



[PATCH] drm: Use strscpy() instead of strscpy_pad()

2025-04-11 Thread Thorsten Blum
kzalloc() already zero-initializes the destination buffers, making
strscpy() sufficient for safely copying the names. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size arguments unnecessary.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 596272149a35..47f2891f3f06 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -128,7 +128,7 @@ struct drm_property *drm_property_create(struct drm_device 
*dev,
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_list);
 
-   strscpy_pad(property->name, name, DRM_PROP_NAME_LEN);
+   strscpy(property->name, name);
 
list_add_tail(&property->head, &dev->mode_config.property_list);
 
@@ -421,7 +421,7 @@ int drm_property_add_enum(struct drm_property *property,
if (!prop_enum)
return -ENOMEM;
 
-   strscpy_pad(prop_enum->name, name, DRM_PROP_NAME_LEN);
+   strscpy(prop_enum->name, name);
prop_enum->value = value;
 
property->values[index] = value;
-- 
2.49.0



[RESEND PATCH] drm: Use strscpy() instead of strscpy_pad()

2025-04-29 Thread Thorsten Blum
kzalloc() already zero-initializes the destination buffers, making
strscpy() sufficient for safely copying the names. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size arguments unnecessary.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 596272149a35..47f2891f3f06 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -128,7 +128,7 @@ struct drm_property *drm_property_create(struct drm_device 
*dev,
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_list);
 
-   strscpy_pad(property->name, name, DRM_PROP_NAME_LEN);
+   strscpy(property->name, name);
 
list_add_tail(&property->head, &dev->mode_config.property_list);
 
@@ -421,7 +421,7 @@ int drm_property_add_enum(struct drm_property *property,
if (!prop_enum)
return -ENOMEM;
 
-   strscpy_pad(prop_enum->name, name, DRM_PROP_NAME_LEN);
+   strscpy(prop_enum->name, name);
prop_enum->value = value;
 
property->values[index] = value;
-- 
2.49.0



[PATCH] drm/gma500: Replace deprecated strncpy() with strscpy()

2025-02-25 Thread Thorsten Blum
strncpy() is deprecated for NUL-terminated destination buffers. Use
strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

Link: https://github.com/KSPP/linux/issues/90
Cc: linux-harden...@vger.kernel.org
Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/gma500/cdv_intel_dp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/gma500/cdv_intel_dp.c 
b/drivers/gpu/drm/gma500/cdv_intel_dp.c
index cc2ed9b3fd2d..ca7f59ff1fda 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_dp.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_dp.c
@@ -855,8 +855,7 @@ cdv_intel_dp_i2c_init(struct gma_connector *connector,
 
memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
intel_dp->adapter.owner = THIS_MODULE;
-   strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 
1);
-   intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
+   strscpy(intel_dp->adapter.name, name);
intel_dp->adapter.algo_data = &intel_dp->algo;
intel_dp->adapter.dev.parent = connector->base.kdev;
 
-- 
2.48.1




[PATCH RESEND] drm: Use strscpy() instead of strscpy_pad()

2025-07-16 Thread Thorsten Blum
kzalloc() already zero-initializes the destination buffers, making
strscpy() sufficient for safely copying the names. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size arguments unnecessary.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 596272149a35..47f2891f3f06 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -128,7 +128,7 @@ struct drm_property *drm_property_create(struct drm_device 
*dev,
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_list);
 
-   strscpy_pad(property->name, name, DRM_PROP_NAME_LEN);
+   strscpy(property->name, name);
 
list_add_tail(&property->head, &dev->mode_config.property_list);
 
@@ -421,7 +421,7 @@ int drm_property_add_enum(struct drm_property *property,
if (!prop_enum)
return -ENOMEM;
 
-   strscpy_pad(prop_enum->name, name, DRM_PROP_NAME_LEN);
+   strscpy(prop_enum->name, name);
prop_enum->value = value;
 
property->values[index] = value;
-- 
2.50.1



[PATCH RESEND] drm: Use strscpy() instead of strscpy_pad()

2025-05-21 Thread Thorsten Blum
kzalloc() already zero-initializes the destination buffers, making
strscpy() sufficient for safely copying the names. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size arguments unnecessary.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 596272149a35..47f2891f3f06 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -128,7 +128,7 @@ struct drm_property *drm_property_create(struct drm_device 
*dev,
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_list);
 
-   strscpy_pad(property->name, name, DRM_PROP_NAME_LEN);
+   strscpy(property->name, name);
 
list_add_tail(&property->head, &dev->mode_config.property_list);
 
@@ -421,7 +421,7 @@ int drm_property_add_enum(struct drm_property *property,
if (!prop_enum)
return -ENOMEM;
 
-   strscpy_pad(prop_enum->name, name, DRM_PROP_NAME_LEN);
+   strscpy(prop_enum->name, name);
prop_enum->value = value;
 
property->values[index] = value;
-- 
2.49.0



[PATCH RESEND] drm: Use strscpy() instead of strscpy_pad()

2025-06-19 Thread Thorsten Blum
kzalloc() already zero-initializes the destination buffers, making
strscpy() sufficient for safely copying the names. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size arguments unnecessary.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 596272149a35..47f2891f3f06 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -128,7 +128,7 @@ struct drm_property *drm_property_create(struct drm_device 
*dev,
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_list);
 
-   strscpy_pad(property->name, name, DRM_PROP_NAME_LEN);
+   strscpy(property->name, name);
 
list_add_tail(&property->head, &dev->mode_config.property_list);
 
@@ -421,7 +421,7 @@ int drm_property_add_enum(struct drm_property *property,
if (!prop_enum)
return -ENOMEM;
 
-   strscpy_pad(prop_enum->name, name, DRM_PROP_NAME_LEN);
+   strscpy(prop_enum->name, name);
prop_enum->value = value;
 
property->values[index] = value;
-- 
2.49.0



[PATCH RESEND] drm: Use strscpy() instead of strscpy_pad()

2025-08-17 Thread Thorsten Blum
kzalloc() already zero-initializes the destination buffers, making
strscpy() sufficient for safely copying the names. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size arguments unnecessary.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 596272149a35..47f2891f3f06 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -128,7 +128,7 @@ struct drm_property *drm_property_create(struct drm_device 
*dev,
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_list);
 
-   strscpy_pad(property->name, name, DRM_PROP_NAME_LEN);
+   strscpy(property->name, name);
 
list_add_tail(&property->head, &dev->mode_config.property_list);
 
@@ -421,7 +421,7 @@ int drm_property_add_enum(struct drm_property *property,
if (!prop_enum)
return -ENOMEM;
 
-   strscpy_pad(prop_enum->name, name, DRM_PROP_NAME_LEN);
+   strscpy(prop_enum->name, name);
prop_enum->value = value;
 
property->values[index] = value;
-- 
2.50.1



[PATCH RESEND] drm: Use strscpy() instead of strscpy_pad()

2025-09-08 Thread Thorsten Blum
kzalloc() already zero-initializes the destination buffers, making
strscpy() sufficient for safely copying the names. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size arguments unnecessary.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/drm_property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 596272149a35..47f2891f3f06 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -128,7 +128,7 @@ struct drm_property *drm_property_create(struct drm_device 
*dev,
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_list);
 
-   strscpy_pad(property->name, name, DRM_PROP_NAME_LEN);
+   strscpy(property->name, name);
 
list_add_tail(&property->head, &dev->mode_config.property_list);
 
@@ -421,7 +421,7 @@ int drm_property_add_enum(struct drm_property *property,
if (!prop_enum)
return -ENOMEM;
 
-   strscpy_pad(prop_enum->name, name, DRM_PROP_NAME_LEN);
+   strscpy(prop_enum->name, name);
prop_enum->value = value;
 
property->values[index] = value;
-- 
2.51.0



[PATCH] drm/amdgpu: Replace kzalloc + copy_from_user with memdup_user

2025-09-08 Thread Thorsten Blum
Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify ta_if_load_debugfs_write() and
ta_if_invoke_debugfs_write().

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 20 ++--
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
index 38face981c3e..6e8aad91bcd3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
@@ -171,13 +171,9 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp, 
const char *buf, size_t
 
copy_pos += sizeof(uint32_t);
 
-   ta_bin = kzalloc(ta_bin_len, GFP_KERNEL);
-   if (!ta_bin)
-   return -ENOMEM;
-   if (copy_from_user((void *)ta_bin, &buf[copy_pos], ta_bin_len)) {
-   ret = -EFAULT;
-   goto err_free_bin;
-   }
+   ta_bin = memdup_user(&buf[copy_pos], ta_bin_len);
+   if (IS_ERR(ta_bin))
+   return PTR_ERR(ta_bin);
 
/* Set TA context and functions */
set_ta_context_funcs(psp, ta_type, &context);
@@ -327,13 +323,9 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, 
const char *buf, size
return -EFAULT;
copy_pos += sizeof(uint32_t);
 
-   shared_buf = kzalloc(shared_buf_len, GFP_KERNEL);
-   if (!shared_buf)
-   return -ENOMEM;
-   if (copy_from_user((void *)shared_buf, &buf[copy_pos], shared_buf_len)) 
{
-   ret = -EFAULT;
-   goto err_free_shared_buf;
-   }
+   shared_buf = memdup_user(&buf[copy_pos], shared_buf_len);
+   if (IS_ERR(shared_buf))
+   return PTR_ERR(shared_buf);
 
set_ta_context_funcs(psp, ta_type, &context);
 
-- 
2.51.0



[PATCH] accel/habanalabs: Replace kmalloc_array + copy_from_user with memdup_array_user

2025-09-08 Thread Thorsten Blum
Replace kmalloc_array() followed by copy_from_user() with
memdup_array_user() to improve and simplify cs_ioctl_engine_cores(),
cs_ioctl_engines(), and hl_multi_cs_wait_ioctl().

Remove the unused variable 'size_to_copy' from hl_multi_cs_wait_ioctl().

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 .../habanalabs/common/command_submission.c| 34 +--
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/drivers/accel/habanalabs/common/command_submission.c 
b/drivers/accel/habanalabs/common/command_submission.c
index dee487724918..a5e339eb7a4f 100644
--- a/drivers/accel/habanalabs/common/command_submission.c
+++ b/drivers/accel/habanalabs/common/command_submission.c
@@ -2481,14 +2481,10 @@ static int cs_ioctl_engine_cores(struct hl_fpriv 
*hpriv, u64 engine_cores,
}
 
engine_cores_arr = (void __user *) (uintptr_t) engine_cores;
-   cores = kmalloc_array(num_engine_cores, sizeof(u32), GFP_KERNEL);
-   if (!cores)
-   return -ENOMEM;
-
-   if (copy_from_user(cores, engine_cores_arr, num_engine_cores * 
sizeof(u32))) {
+   cores = memdup_array_user(engine_cores_arr, num_engine_cores, 
sizeof(u32));
+   if (IS_ERR(cores)) {
dev_err(hdev->dev, "Failed to copy core-ids array from user\n");
-   kfree(cores);
-   return -EFAULT;
+   return PTR_ERR(cores);
}
 
rc = hdev->asic_funcs->set_engine_cores(hdev, cores, num_engine_cores, 
core_command);
@@ -2523,14 +2519,10 @@ static int cs_ioctl_engines(struct hl_fpriv *hpriv, u64 
engines_arr_user_addr,
}
 
engines_arr = (void __user *) (uintptr_t) engines_arr_user_addr;
-   engines = kmalloc_array(num_engines, sizeof(u32), GFP_KERNEL);
-   if (!engines)
-   return -ENOMEM;
-
-   if (copy_from_user(engines, engines_arr, num_engines * sizeof(u32))) {
+   engines = memdup_array_user(engines_arr, num_engines, sizeof(u32));
+   if (IS_ERR(engines)) {
dev_err(hdev->dev, "Failed to copy engine-ids array from 
user\n");
-   kfree(engines);
-   return -EFAULT;
+   return PTR_ERR(engines);
}
 
rc = hdev->asic_funcs->set_engines(hdev, engines, num_engines, command);
@@ -3013,7 +3005,6 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, 
void *data)
struct hl_ctx *ctx = hpriv->ctx;
struct hl_fence **fence_arr;
void __user *seq_arr;
-   u32 size_to_copy;
u64 *cs_seq_arr;
u8 seq_arr_len;
int rc, i;
@@ -3037,19 +3028,12 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv 
*hpriv, void *data)
return -EINVAL;
}
 
-   /* allocate memory for sequence array */
-   cs_seq_arr =
-   kmalloc_array(seq_arr_len, sizeof(*cs_seq_arr), GFP_KERNEL);
-   if (!cs_seq_arr)
-   return -ENOMEM;
-
/* copy CS sequence array from user */
seq_arr = (void __user *) (uintptr_t) args->in.seq;
-   size_to_copy = seq_arr_len * sizeof(*cs_seq_arr);
-   if (copy_from_user(cs_seq_arr, seq_arr, size_to_copy)) {
+   cs_seq_arr = memdup_array_user(seq_arr, seq_arr_len, 
sizeof(*cs_seq_arr));
+   if (IS_ERR(cs_seq_arr)) {
dev_err(hdev->dev, "Failed to copy multi-cs sequence array from 
user\n");
-   rc = -EFAULT;
-   goto free_seq_arr;
+   return PTR_ERR(cs_seq_arr);
}
 
/* allocate array for the fences */
-- 
2.51.0



[PATCH] drm/amdkfd: Replace kzalloc + copy_from_user with memdup_user

2025-09-08 Thread Thorsten Blum
Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify kfd_ioctl_set_cu_mask().

Return early if an error occurs and remove the obsolete 'out' label.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 828a9ceef1e7..5d58a7bf309a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -521,15 +521,10 @@ static int kfd_ioctl_set_cu_mask(struct file *filp, 
struct kfd_process *p,
cu_mask_size = sizeof(uint32_t) * (max_num_cus/32);
}
 
-   minfo.cu_mask.ptr = kzalloc(cu_mask_size, GFP_KERNEL);
-   if (!minfo.cu_mask.ptr)
-   return -ENOMEM;
-
-   retval = copy_from_user(minfo.cu_mask.ptr, cu_mask_ptr, cu_mask_size);
-   if (retval) {
+   minfo.cu_mask.ptr = memdup_user(cu_mask_ptr, cu_mask_size);
+   if (IS_ERR(minfo.cu_mask.ptr)) {
pr_debug("Could not copy CU mask from userspace");
-   retval = -EFAULT;
-   goto out;
+   return PTR_ERR(minfo.cu_mask.ptr);
}
 
mutex_lock(&p->mutex);
@@ -538,7 +533,6 @@ static int kfd_ioctl_set_cu_mask(struct file *filp, struct 
kfd_process *p,
 
mutex_unlock(&p->mutex);
 
-out:
kfree(minfo.cu_mask.ptr);
return retval;
 }
-- 
2.51.0



[PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user

2025-09-12 Thread Thorsten Blum
Replace kmalloc() followed by copy_from_user() with memdup_user() to
improve and simplify kfd_criu_restore_queue().

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 .../amd/amdkfd/kfd_process_queue_manager.c| 22 +--
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
index 7fbb5c274ccc..70c17a12cadf 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
@@ -1004,13 +1004,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
if (*priv_data_offset + sizeof(*q_data) > max_priv_data_size)
return -EINVAL;
 
-   q_data = kmalloc(sizeof(*q_data), GFP_KERNEL);
-   if (!q_data)
-   return -ENOMEM;
-
-   ret = copy_from_user(q_data, user_priv_ptr + *priv_data_offset, 
sizeof(*q_data));
-   if (ret) {
-   ret = -EFAULT;
+   q_data = memdup_user(user_priv_ptr + *priv_data_offset, 
sizeof(*q_data));
+   if (IS_ERR(q_data)) {
+   ret = PTR_ERR(q_data);
goto exit;
}
 
@@ -1022,15 +1018,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
goto exit;
}
 
-   q_extra_data = kmalloc(q_extra_data_size, GFP_KERNEL);
-   if (!q_extra_data) {
-   ret = -ENOMEM;
-   goto exit;
-   }
-
-   ret = copy_from_user(q_extra_data, user_priv_ptr + *priv_data_offset, 
q_extra_data_size);
-   if (ret) {
-   ret = -EFAULT;
+   q_extra_data = memdup_user(user_priv_ptr + *priv_data_offset, 
q_extra_data_size);
+   if (IS_ERR(q_extra_data)) {
+   ret = PTR_ERR(q_extra_data);
goto exit;
}
 
-- 
2.51.0



[PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user()

2025-09-02 Thread Thorsten Blum
Replace kmalloc() followed by copy_from_user() with memdup_user() to
improve and simplify set_context_image(), and to silence the following
Coccinelle/coccicheck warning reported by memdup_user.cocci:

  WARNING opportunity for memdup_user

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
Resending this (with updated patch subject and description) because the
CI logs [1] from my first submission [2] about a year ago are no longer
available.

[1] https://patchwork.freedesktop.org/series/139319/
[2] https://lore.kernel.org/lkml/20240925141750.51198-1-thorsten.b...@linux.dev/
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c 
b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index 15835952352e..ed6599694835 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -2158,18 +2158,12 @@ static int set_context_image(struct i915_gem_context 
*ctx,
goto out_ce;
}
 
-   state = kmalloc(ce->engine->context_size, GFP_KERNEL);
-   if (!state) {
-   ret = -ENOMEM;
+   state = memdup_user(u64_to_user_ptr(user.image), 
ce->engine->context_size);
+   if (IS_ERR(state)) {
+   ret = PTR_ERR(state);
goto out_ce;
}
 
-   if (copy_from_user(state, u64_to_user_ptr(user.image),
-  ce->engine->context_size)) {
-   ret = -EFAULT;
-   goto out_state;
-   }
-
shmem_state = shmem_create_from_data(ce->engine->name,
 state, ce->engine->context_size);
if (IS_ERR(shmem_state)) {
-- 
2.51.0



[PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user

2025-09-17 Thread Thorsten Blum
Replace kcalloc() followed by copy_from_user() with memdup_array_user()
to improve and simplify both __qaic_execute_bo_ioctl() and
qaic_perf_stats_bo_ioctl().

In __qaic_execute_bo_ioctl(), return early if an error occurs and remove
the obsolete 'free_exec' label.

Since memdup_array_user() already checks for multiplication overflow,
remove the manual check in __qaic_execute_bo_ioctl(). Remove any unused
local variables accordingly.

Since 'ret = copy_from_user()' has been removed, initialize 'ret = 0' to
preserve the same return value on success.

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/accel/qaic/qaic_data.c | 34 +-
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index 202bdca58847..adabc4028bb2 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -1295,8 +1295,6 @@ static int __qaic_execute_bo_ioctl(struct drm_device 
*dev, void *data, struct dr
int usr_rcu_id, qdev_rcu_id;
struct qaic_device *qdev;
struct qaic_user *usr;
-   u8 __user *user_data;
-   unsigned long n;
u64 received_ts;
u32 queue_level;
u64 submit_ts;
@@ -1309,20 +1307,12 @@ static int __qaic_execute_bo_ioctl(struct drm_device 
*dev, void *data, struct dr
received_ts = ktime_get_ns();
 
size = is_partial ? sizeof(struct qaic_partial_execute_entry) : 
sizeof(*exec);
-   n = (unsigned long)size * args->hdr.count;
-   if (args->hdr.count == 0 || n / args->hdr.count != size)
+   if (args->hdr.count == 0)
return -EINVAL;
 
-   user_data = u64_to_user_ptr(args->data);
-
-   exec = kcalloc(args->hdr.count, size, GFP_KERNEL);
-   if (!exec)
-   return -ENOMEM;
-
-   if (copy_from_user(exec, user_data, n)) {
-   ret = -EFAULT;
-   goto free_exec;
-   }
+   exec = memdup_array_user(u64_to_user_ptr(args->data), args->hdr.count, 
size);
+   if (IS_ERR(exec))
+   return PTR_ERR(exec);
 
usr = file_priv->driver_priv;
usr_rcu_id = srcu_read_lock(&usr->qddev_lock);
@@ -1383,7 +1373,6 @@ static int __qaic_execute_bo_ioctl(struct drm_device 
*dev, void *data, struct dr
srcu_read_unlock(&qdev->dev_lock, qdev_rcu_id);
 unlock_usr_srcu:
srcu_read_unlock(&usr->qddev_lock, usr_rcu_id);
-free_exec:
kfree(exec);
return ret;
 }
@@ -1736,7 +1725,8 @@ int qaic_perf_stats_bo_ioctl(struct drm_device *dev, void 
*data, struct drm_file
struct qaic_device *qdev;
struct qaic_user *usr;
struct qaic_bo *bo;
-   int ret, i;
+   int ret = 0;
+   int i;
 
usr = file_priv->driver_priv;
usr_rcu_id = srcu_read_lock(&usr->qddev_lock);
@@ -1757,18 +1747,12 @@ int qaic_perf_stats_bo_ioctl(struct drm_device *dev, 
void *data, struct drm_file
goto unlock_dev_srcu;
}
 
-   ent = kcalloc(args->hdr.count, sizeof(*ent), GFP_KERNEL);
-   if (!ent) {
-   ret = -EINVAL;
+   ent = memdup_array_user(u64_to_user_ptr(args->data), args->hdr.count, 
sizeof(*ent));
+   if (IS_ERR(ent)) {
+   ret = PTR_ERR(ent);
goto unlock_dev_srcu;
}
 
-   ret = copy_from_user(ent, u64_to_user_ptr(args->data), args->hdr.count 
* sizeof(*ent));
-   if (ret) {
-   ret = -EFAULT;
-   goto free_ent;
-   }
-
for (i = 0; i < args->hdr.count; i++) {
obj = drm_gem_object_lookup(file_priv, ent[i].handle);
if (!obj) {
-- 
2.51.0



[PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user

2025-09-17 Thread Thorsten Blum
Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify qaic_attach_slice_bo_ioctl().

No functional changes intended.

Signed-off-by: Thorsten Blum 
---
 drivers/accel/qaic/qaic_data.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index 797289e9d780..202bdca58847 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -984,18 +985,12 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, 
void *data, struct drm_fi
 
user_data = u64_to_user_ptr(args->data);
 
-   slice_ent = kzalloc(arg_size, GFP_KERNEL);
-   if (!slice_ent) {
-   ret = -EINVAL;
+   slice_ent = memdup_user(user_data, arg_size);
+   if (IS_ERR(slice_ent)) {
+   ret = PTR_ERR(slice_ent);
goto unlock_dev_srcu;
}
 
-   ret = copy_from_user(slice_ent, user_data, arg_size);
-   if (ret) {
-   ret = -EFAULT;
-   goto free_slice_ent;
-   }
-
obj = drm_gem_object_lookup(file_priv, args->hdr.handle);
if (!obj) {
ret = -ENOENT;
-- 
2.51.0



Re: [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user

2025-09-20 Thread Thorsten Blum
Hi Alex,

On 9. Sep 2025, at 17:35, Alex Deucher wrote:
> Applied.  Thanks!
> 
> On Tue, Sep 9, 2025 at 11:29 AM Thorsten Blum  wrote:
>> 
>> Replace kmalloc() followed by copy_from_user() with memdup_user() to
>> improve and simplify kfd_criu_restore_queue().
>> 
>> No functional changes intended.
>> 
>> Signed-off-by: Thorsten Blum 
>> ---

I just learned that calling kfree() on an error pointer doesn't work, so
this patch should probably be reverted/not applied.

Thanks,
Thorsten



Re: [PATCH RESEND] drm: Use strscpy() instead of strscpy_pad()

2025-09-25 Thread Thorsten Blum
Hi all,

> On 8. Sep 2025, Thorsten Blum wrote:
> 
> kzalloc() already zero-initializes the destination buffers, making
> strscpy() sufficient for safely copying the names. The additional
> NUL-padding performed by strscpy_pad() is unnecessary.
> 
> If the destination buffer has a fixed length, strscpy() automatically
> determines its size using sizeof() when the argument is omitted. This
> makes the explicit size arguments unnecessary.
> 
> No functional changes intended.
> 
> Signed-off-by: Thorsten Blum 
> ---

I've been resending this patch since April and I'm wondering what else I
could do to get this reviewed and/or merged?

The patch still applies to both linux-next and master.

Thanks,
Thorsten



[PATCH RESEND] accel/habanalabs: Replace kmalloc_array + copy_from_user with memdup_array_user

2025-09-27 Thread Thorsten Blum
Replace kmalloc_array() followed by copy_from_user() with
memdup_array_user() to improve and simplify cs_ioctl_engine_cores(),
cs_ioctl_engines(), and hl_multi_cs_wait_ioctl().

Remove the unused variable 'size_to_copy' from hl_multi_cs_wait_ioctl().

No functional changes intended.

Reviewed-by: Karol Wachowski 
Signed-off-by: Thorsten Blum 
---
 .../habanalabs/common/command_submission.c| 34 +--
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/drivers/accel/habanalabs/common/command_submission.c 
b/drivers/accel/habanalabs/common/command_submission.c
index dee487724918..a5e339eb7a4f 100644
--- a/drivers/accel/habanalabs/common/command_submission.c
+++ b/drivers/accel/habanalabs/common/command_submission.c
@@ -2481,14 +2481,10 @@ static int cs_ioctl_engine_cores(struct hl_fpriv 
*hpriv, u64 engine_cores,
}
 
engine_cores_arr = (void __user *) (uintptr_t) engine_cores;
-   cores = kmalloc_array(num_engine_cores, sizeof(u32), GFP_KERNEL);
-   if (!cores)
-   return -ENOMEM;
-
-   if (copy_from_user(cores, engine_cores_arr, num_engine_cores * 
sizeof(u32))) {
+   cores = memdup_array_user(engine_cores_arr, num_engine_cores, 
sizeof(u32));
+   if (IS_ERR(cores)) {
dev_err(hdev->dev, "Failed to copy core-ids array from user\n");
-   kfree(cores);
-   return -EFAULT;
+   return PTR_ERR(cores);
}
 
rc = hdev->asic_funcs->set_engine_cores(hdev, cores, num_engine_cores, 
core_command);
@@ -2523,14 +2519,10 @@ static int cs_ioctl_engines(struct hl_fpriv *hpriv, u64 
engines_arr_user_addr,
}
 
engines_arr = (void __user *) (uintptr_t) engines_arr_user_addr;
-   engines = kmalloc_array(num_engines, sizeof(u32), GFP_KERNEL);
-   if (!engines)
-   return -ENOMEM;
-
-   if (copy_from_user(engines, engines_arr, num_engines * sizeof(u32))) {
+   engines = memdup_array_user(engines_arr, num_engines, sizeof(u32));
+   if (IS_ERR(engines)) {
dev_err(hdev->dev, "Failed to copy engine-ids array from 
user\n");
-   kfree(engines);
-   return -EFAULT;
+   return PTR_ERR(engines);
}
 
rc = hdev->asic_funcs->set_engines(hdev, engines, num_engines, command);
@@ -3013,7 +3005,6 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, 
void *data)
struct hl_ctx *ctx = hpriv->ctx;
struct hl_fence **fence_arr;
void __user *seq_arr;
-   u32 size_to_copy;
u64 *cs_seq_arr;
u8 seq_arr_len;
int rc, i;
@@ -3037,19 +3028,12 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv 
*hpriv, void *data)
return -EINVAL;
}
 
-   /* allocate memory for sequence array */
-   cs_seq_arr =
-   kmalloc_array(seq_arr_len, sizeof(*cs_seq_arr), GFP_KERNEL);
-   if (!cs_seq_arr)
-   return -ENOMEM;
-
/* copy CS sequence array from user */
seq_arr = (void __user *) (uintptr_t) args->in.seq;
-   size_to_copy = seq_arr_len * sizeof(*cs_seq_arr);
-   if (copy_from_user(cs_seq_arr, seq_arr, size_to_copy)) {
+   cs_seq_arr = memdup_array_user(seq_arr, seq_arr_len, 
sizeof(*cs_seq_arr));
+   if (IS_ERR(cs_seq_arr)) {
dev_err(hdev->dev, "Failed to copy multi-cs sequence array from 
user\n");
-   rc = -EFAULT;
-   goto free_seq_arr;
+   return PTR_ERR(cs_seq_arr);
}
 
/* allocate array for the fences */
-- 
2.51.0