Repository navigation
Conversation
Coverity reports HIS_metric_violation (RETURN) for the functions in drivers/rpmsg/rpmsg.c that return from several places. Restructure them to keep the result in a local variable and return once at the end: rpmsg_init_workrx(), rpmsg_create_wqueues(), rpmsg_tickwait(), rpmsg_post(), rpmsg_get_local_cpuname(), rpmsg_get_timestamp(), rpmsg_alloc_buf(), rpmsg_register_callback(), rpmsg_ns_bind(), rpmsg_register(), rpmsg_ioctl_foreach_cb() The goto in rpmsg_register_callback() becomes a loop over the bind list that restarts after each match. No functional change intended. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Coverity reports HIS_metric_violation (RETURN) for the functions in drivers/rpmsg/rpmsg_virtio.c that return from several places. Restructure rpmsg_virtio_buffer_nused(), rpmsg_virtio_dump(), rpmsg_virtio_start_worker() and rpmsg_virtio_probe_cpuname() to return once at the end, nesting the success path instead of returning or jumping on each error. No functional change. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
rpmsg_register_callback() frees the bind record it matched and sets again to walk the list from the start, but kept iterating the list it had just modified. Break out of the walk after the match. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Coverity reports HIS_metric_violation (RETURN) for rpmsg_get_by_rdev() and rpmsg_get_current_wqueue(), which return from two places. Keep the result in a local variable and return once. No functional change. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
The single exit rework inverted the condition: rpmsg_alloc_buf() called ops->alloc_buf() exactly when rpmsg or the op was NULL. Call it only when both are set. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
MISRA C-2012 Rule 8.9: an object should be declared at block scope if its identifier only appears in a single function. g_rpmsg_dev_ops is only used by rpmsg_register(), so move it there as a static const. MISRA C-2012 Rule 10.4: compare the uint16_t nrx with an unsigned constant in rpmsg_init_workrx(). No functional change. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Fix three problems left by the single exit rework: - rpmsg_ns_bind() kept walking the callback list after it had dropped g_rpmsg_lock and bound the first match. Stop at the first match. - rpmsg_ns_bind() only released g_rpmsg_lock when the bind record was allocated, so an allocation failure returned with the lock held. Release it in both cases. - rpmsg_register_callback() set again only once, so the bind list of every device after the first was not walked. Set it for each device. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
MISRA C-2012 Rule 10.4: both operands of an arithmetic operator shall have the same essential type category. The ring indices and counts in rpmsg_virtio_buffer_nused() and rpmsg_virtio_dump_buffer() are uint16_t in the vring but were handled as int. Return and store them as uint16_t, compare with unsigned constants and print them with %u. No functional change. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
MISRA C-2012 Rule 9.1: the value of an object with automatic storage duration shall not be read before it has been set. Coverity cannot see that nxsem_get_value() and virtio_read_config_member() always fill in semcount and shmbuf_pa0/1, so initialize them. No functional change. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
MISRA C-2012 Rule 8.9: an object should be declared at block scope if its identifier only appears in a single function. g_rpmsg_virtio_ops is only used by rpmsg_virtio_start_worker(), so move it there as a static const. No functional change. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
|
xiaoxiang781216
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Static analysis cleanups of the rpmsg core (
drivers/rpmsg/rpmsg.c) andthe rpmsg virtio transport (
drivers/rpmsg/rpmsg_virtio.c), found byCoverity (HIS metrics and MISRA C-2012), and three fixes to bugs the
first rework introduced, kept as separate commits in the order they were
made.
use a single exit point(3 commits, HIS_metric_violation RETURN):functions that returned from several places now keep the result in a
local variable and return once. The
goto againloop inrpmsg_register_callback()becomes awhileloop that restarts thewalk of the bind list after each match; the
goto errpaths inrpmsg_create_wqueues()andrpmsg_virtio_probe_cpuname()becomeelsebranches.restart the bind list walk after each match,fix the check in rpmsg_alloc_buf(),fix rpmsg_ns_bind() and rpmsg_register_callback(): fixes to thefirst commit (missing
breaks, an inverted condition,againsetonly once, the lock release in
rpmsg_ns_bind()).define g_rpmsg_dev_ops / g_rpmsg_virtio_ops in its only user(Rule 8.9): the two ops tables move into the only function that uses
them, as
static const.use unsigned types for ring counts(Rule 10.4): the vring indicesand counts in
rpmsg_virtio_buffer_nused()andrpmsg_virtio_dump_buffer()areuint16_t, printed with%u.initialize variables set through a pointer(Rule 9.1).One behaviour change: on master
rpmsg_ns_bind()returns withg_rpmsg_lockstill read-held when it fails to allocate the bindrecord. After this PR the lock is released on that path too.
The intermediate commits between the first one and its fixes are not
bisect-safe for the bind paths; the series as a whole is what was
tested.
Impact
No API, Kconfig or behaviour change, except the lock release above on
an out-of-memory path.
Testing
Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
Every commit builds sim:rpserver, sim:rpproxy, qemu-armv8a:rpserver and
qemu-armv8a:rpproxy with no warnings.
sim:rpserver + sim:rpproxy and qemu-armv8a:rpserver + qemu-armv8a:rpproxy
(unchanged configs), same cases on master and on this PR: the fixed
rpmsg cases (dump, ping, rpmsgfs mount and read), plus
rpmsg ping all 200 2048 3 0on both nodes andrpmsg dump all(verbose, walks
rpmsg_virtio_dump()andrpmsg_virtio_dump_buffer())on both nodes.
rpmsg dump alloutput (endpoints, vq state, buffer counts; addresses and ring indices masked)rpmsg ping all 200 2048 3 0avg, server / proxyThe name service paths in
rpmsg_ns_bind()were checked with atest-only
syslog()(not in this PR) on the "no service yet, keep abind record" branch and on the replay branch of
rpmsg_register_callback(): on sim the same three records are kept onevery boot, on master and on this PR (3 runs each):
Not tested: the replay branch of
rpmsg_register_callback()(no servicein these configs registers after its name was announced), and the
error paths (allocation,
register_driver(),rpmsg_init_vdev()andwork queue creation failures).
No regression in rpmsg: sim:rpserver/rpproxy and qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, rpmsgfs; 22/22). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current master needs for nxinit to start nsh there; unrelated to this change.