Skip to content

Fix Linux >=7.2 compatibility by replacing strncpy with strscpy - #10121

Open
IsaacJT wants to merge 1 commit into
Xilinx:masterfrom
IsaacJT:itrue/fix-kernel-7.2
Open

IsaacJT wants to merge 1 commit into
Xilinx:masterfrom
IsaacJT:itrue/fix-kernel-7.2

Conversation

@IsaacJT

@IsaacJT IsaacJT commented Oct 16, 2026

Copy link
Copy Markdown

Problem solved by the commit

The strncpy function was removed in Linux 7.2, causing the kernel module build to fail with the following error (among others):

../xocl_subdev.c: In function ‘__xocl_subdev_create’: ../xocl_subdev.c:623:33: error: implicit declaration of function ‘strncpy’ [-Wimplicit-function-declaration]
  623 |                                 strncpy(subdev->res_name +
      |                                 ^~~~~~~
../xocl_subdev.c:22:1: note: include ‘<string.h>’ or provide a declaration of ‘strncpy’
   21 | #include "version.h"
  +++ |+#include <string.h>
   22 |
../xocl_subdev.c:623:33: warning: incompatible implicit declaration of built-in function ‘strncpy’ [-Wbuiltin-declaration-mismatch]
  623 |                                 strncpy(subdev->res_name +
      |                                 ^~~~~~~
../xocl_subdev.c:623:33: note: include ‘<string.h>’ or provide a declaration of ‘strncpy’
../xocl_subdev.c: In function ‘xocl_fetch_dynamic_platform’:
../xocl_subdev.c:1438:25: warning: incompatible implicit declaration of built-in function ‘strncpy’ [-Wbuiltin-declaration-mismatch]
 1438 |                         strncpy(core->vbnv_cache, dsa_map[i].vbnv,
      |                         ^~~~~~~
../xocl_subdev.c:1438:25: note: include ‘<string.h>’ or provide a declaration of ‘strncpy’

Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered

Upstream commit which removed strncpy support: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1a3746ccbb0a97bed3c06ccde6b880013b1dddc1

How problem was solved, alternative solutions (if any) and why they were rejected

Invocations of the strncpy function were replaced by strscpy, which copies a string and ensures it is NULL-terminated.

Risks (if any) associated the changes in the commit

strscpy has been around for over 10 years, so there should be no risks with kernel versions involved.

One potential risk is that a section of code is relying on some specific kind of behaviour from strncpy (intentionally or otherwise) that strscpy does not replicate.

What has been tested and how, request additional testing if necessary

Kernel module compilation has been performed on kernels 7.2 (Debian unstable) and 7.3 (Ubuntu 26.10)

@xrt-pr-bot

xrt-pr-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

⚠️ Authorization Failed

@IsaacJT is not a repository collaborator.

To proceed:

  • XRT Admins: Add the build label to authorize this PR build
  • OR Add @IsaacJT as a repository collaborator

The strncpy function was removed in Linux 7.2. Replace all instances of
it with strscpy to allow building on kernel versions >=7.2, resolving
the following error, among others:

../xocl_subdev.c: In function ‘__xocl_subdev_create’:
../xocl_subdev.c:623:33: error: implicit declaration of function ‘strncpy’ [-Wimplicit-function-declaration]
  623 |                                 strncpy(subdev->res_name +
      |                                 ^~~~~~~
../xocl_subdev.c:22:1: note: include ‘<string.h>’ or provide a declaration of ‘strncpy’
   21 | #include "version.h"
  +++ |+#include <string.h>
   22 |
../xocl_subdev.c:623:33: warning: incompatible implicit declaration of built-in function ‘strncpy’ [-Wbuiltin-declaration-mismatch]
  623 |                                 strncpy(subdev->res_name +
      |                                 ^~~~~~~
../xocl_subdev.c:623:33: note: include ‘<string.h>’ or provide a declaration of ‘strncpy’
../xocl_subdev.c: In function ‘xocl_fetch_dynamic_platform’:
../xocl_subdev.c:1438:25: warning: incompatible implicit declaration of built-in function ‘strncpy’ [-Wbuiltin-declaration-mismatch]
 1438 |                         strncpy(core->vbnv_cache, dsa_map[i].vbnv,
      |                         ^~~~~~~
../xocl_subdev.c:1438:25: note: include ‘<string.h>’ or provide a declaration of ‘strncpy’

Signed-off-by: Isaac True <isaac@is.having.coffee>
@IsaacJT
IsaacJT force-pushed the itrue/fix-kernel-7.2 branch from f89710b to f0cdb04 Compare October 16, 2026 15:57
@xrt-pr-bot

xrt-pr-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

⚠️ Authorization Failed

@IsaacJT is not a repository collaborator.

To proceed:

  • XRT Admins: Add the build label to authorize this PR build
  • OR Add @IsaacJT as a repository collaborator

1 similar comment
@xrt-pr-bot

xrt-pr-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

⚠️ Authorization Failed

@IsaacJT is not a repository collaborator.

To proceed:

  • XRT Admins: Add the build label to authorize this PR build
  • OR Add @IsaacJT as a repository collaborator

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant