From f7e9dc3ab595f043ff5c8d804dbf9579fad72c72 Mon Sep 17 00:00:00 2001 From: bernard Date: Sun, 18 Oct 2026 19:33:53 +0800 Subject: [PATCH] [libc] use DFS file operations in poll - resolve fops from dfs_file instead of vnode directly - keep compatibility with both DFSv1 and DFSv2 - validate fops before dereferencing to avoid NULL access --- components/libc/posix/io/poll/poll.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/libc/posix/io/poll/poll.c b/components/libc/posix/io/poll/poll.c index 36672160816d..1e4f5effb426 100644 --- a/components/libc/posix/io/poll/poll.c +++ b/components/libc/posix/io/poll/poll.c @@ -214,16 +214,28 @@ static int do_pollfd(struct pollfd *pollfd, rt_pollreq_t *req) if (fd >= 0) { struct dfs_file *f = fd_get(fd); + const struct dfs_file_ops *fops = RT_NULL; mask = POLLNVAL; if (f) { +#ifdef RT_USING_DFS_V2 + fops = f->fops; +#else + if (f->vnode) + { + fops = f->vnode->fops; + } +#endif + } + if (fops) + { mask = POLLMASK_DEFAULT; - if (f->vnode->fops->poll) + if (fops->poll) { req->_key = pollfd->events | POLLERR | POLLHUP; - mask = f->vnode->fops->poll(f, req); + mask = fops->poll(f, req); /* dealwith the device return error -1*/ if (mask < 0)