-
Notifications
You must be signed in to change notification settings - Fork 481
c_str! NUL checks and CBounedStr
#258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rust
Are you sure you want to change the base?
Conversation
|
@ojeda I've seen a weird rustdoc triple error in https://github.com/Rust-for-Linux/linux/runs/2537235143?check_suite_focus=true. I then tried to add Which doesn't make any sense to me since the same target json is specified but somehow rustc and rustdoc uses different hash. Do you have any clue? |
|
@nbdd0121, I'm having a hard time convincing myself the extra complexity is worth the benefits they're bringing. (I also think we should only resort in proc macros when no other reasonable alternatives exist.) Would you mind sharing more of your thoughts on this? |
A few reasons:
As for complexity, I am doing a refactoring to rename libmodule to libmacros and move c_str macros there, Hopefully after refactoring the structure will be less complex. |
|
Also note that the |
This is indeed nice, but I don't think it is essential, especially because it does not affect safety (even though it of course may affect correctness).
Also nice to have, but do we have a case where we'd like to use
Where do we need this? The descriptor table in devices? I'm still not convinced these niceties are worth the extra complexity. I'm especially concerned about when we're trying to push this upstream: I'd rather avoid turning reviewers off if they look at this and think "Woah, we need this much extra code to handle C strings?". (I would certainly feel this way, and do a little bit about modules too...) (Also, apologies for encouraging you to do the work before a discussion [that you rightfully sought in the meeting]. Next time we should discuss beforehand, perhaps on the mailing list or a Github issue before spending time on the implementation.) |
The restriction of
static DEVICE_ID: of_device_id = of_device_id {
compatible: c_bounded_str!("some string").expand_to_char_array()
/* ... */
}(or even define another macro that expand to this, say
It's actually just a few lines. I'ved pushed the refactored code (WIP), you can see it is just a few lines. Much of the code is the infrastructure. With these infrastructure we can actually simplify the |
|
Some additional justification for vendoring buffer and lit from syn:
|
|
Will split into multiple PRs. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I tested your PR by merging it into #276. Consider me as this PR's very first customer. Customer is king :) It allows me to eliminate the runtime check that verifies whether the string fits in 128 characters. Also, the unsafe call to A few comments:
let of_match_tbl = OfMatchTable::new(c_bounded_str!("brcm,bcm2835-rng").relax_bound())?;It would be more intuitive if there were no need for
|
I think so. It might make sense to allow using a custom name for the non-existent symbol that is referenced to cause the link error. If using a linker that accepts arbitrary symbol names, maybe even include the assertion itself.
Would the following work? The |
|
The |
This comment has been minimized.
This comment has been minimized.
Rust can only use
This is indeed a bit cryptic, but at least it provides some info about the crate and function that fails the assertion. If you specify manually the bound in Perhaps in the future we can have a tool that extracts the callgraph from disassembly or debuginfo and gives you a static stack trace, but that's a large amount of work and probably wouldn't worth the effort until we're upstreamed :) |
Speaking purely from a user's POV, I would prefer to see
True! TBH I'm very happy that this works. Good build time checks are awesome! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
`CBoundedStr<N>` is a `CStr` with length known to be less than `N`. It can be used in cases where a known length limit exists. Signed-off-by: Gary Guo <[email protected]>
|
Review of
|
[ Upstream commit 178aa33 ] If streamon/streamoff calls are imbalanced, such as when exiting an application with Ctrl+C when streaming, the m2m usage_count will never reach zero and the ISI channel won't be freed. Besides from that, if the input line width is more than 2K, it will trigger a WARN_ON(): [ 59.222120] ------------[ cut here ]------------ [ 59.226758] WARNING: drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c:631 at mxc_isi_channel_chain+0xa4/0x120, CPU#4: v4l2-ctl/654 [ 59.238569] Modules linked in: ap1302 [ 59.242231] CPU: 4 UID: 0 PID: 654 Comm: v4l2-ctl Not tainted 6.16.0-rc4-next-20250704-06511-gff0e002d480a-dirty Rust-for-Linux#258 PREEMPT [ 59.253597] Hardware name: NXP i.MX95 15X15 board (DT) [ 59.258720] pstate: 80400009 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 59.265669] pc : mxc_isi_channel_chain+0xa4/0x120 [ 59.270358] lr : mxc_isi_channel_chain+0x44/0x120 [ 59.275047] sp : ffff8000848c3b40 [ 59.278348] x29: ffff8000848c3b40 x28: ffff0000859b4c98 x27: ffff800081939f00 [ 59.285472] x26: 000000000000000a x25: ffff0000859b4cb8 x24: 0000000000000001 [ 59.292597] x23: ffff0000816f4760 x22: ffff0000816f4258 x21: ffff000084ceb780 [ 59.299720] x20: ffff000084342ff8 x19: ffff000084340000 x18: 0000000000000000 [ 59.306845] x17: 0000000000000000 x16: 0000000000000000 x15: 0000ffffdb369e1c [ 59.313969] x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 [ 59.321093] x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 [ 59.328217] x8 : ffff8000848c3d48 x7 : ffff800081930b30 x6 : ffff800081930b30 [ 59.335340] x5 : ffff0000859b6000 x4 : ffff80008193ae80 x3 : ffff800081022420 [ 59.342464] x2 : ffff0000852f6900 x1 : 0000000000000001 x0 : ffff000084341000 [ 59.349590] Call trace: [ 59.352025] mxc_isi_channel_chain+0xa4/0x120 (P) [ 59.356722] mxc_isi_m2m_streamon+0x160/0x20c [ 59.361072] v4l_streamon+0x24/0x30 [ 59.364556] __video_do_ioctl+0x40c/0x4a0 [ 59.368560] video_usercopy+0x2bc/0x690 [ 59.372382] video_ioctl2+0x18/0x24 [ 59.375857] v4l2_ioctl+0x40/0x60 [ 59.379168] __arm64_sys_ioctl+0xac/0x104 [ 59.383172] invoke_syscall+0x48/0x104 [ 59.386916] el0_svc_common.constprop.0+0xc0/0xe0 [ 59.391613] do_el0_svc+0x1c/0x28 [ 59.394915] el0_svc+0x34/0xf4 [ 59.397966] el0t_64_sync_handler+0xa0/0xe4 [ 59.402143] el0t_64_sync+0x198/0x19c [ 59.405801] ---[ end trace 0000000000000000 ]--- Address this issue by moving the streaming preparation and cleanup to the vb2 .prepare_streaming() and .unprepare_streaming() operations. This also simplifies the driver by allowing direct usage of the v4l2_m2m_ioctl_streamon() and v4l2_m2m_ioctl_streamoff() helpers. Fixes: cf21f32 ("media: nxp: Add i.MX8 ISI driver") Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guoniu Zhou <[email protected]> Co-developed-by: Laurent Pinchart <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]> Tested-by: Guoniu Zhou <[email protected]> Reviewed-by: Frank Li <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> [ added bypass parameter to mxc_isi_channel_chain() call ] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
Implement
CBoundedStr<N>.Depends on #257
Depends on #273