Skip to content

hostmot2: fix input bounds, divisors and PWM clamping - #4661

Open
sleepybishop wants to merge 14 commits into
LinuxCNC:masterfrom
sleepybishop:hostmot-fixes
Open

sleepybishop wants to merge 14 commits into
LinuxCNC:masterfrom
sleepybishop:hostmot-fixes

Conversation

@sleepybishop

@sleepybishop sleepybishop commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Split from #4488 as requested. Adds UART/BSPI input and LLIO checks, guards scan-rate and resolver divisors, bounds connector-name access, and fixes RPi3 SPI speed decoding and negative B/C PWM clamping. Existing successful API returns and UART/BSPI -1 errors are preserved.

Local builds pass. Hardware coverage remains incomplete.

Use integer ceiling when storing clamped scan rates so the following cycle cannot calculate an out-of-range divisor again. Keep the existing control flow and divisor limit.

Test startup and runtime clamps, unchanged valid rates, and repeated cycles across all scan widths with three clock frequencies.
@sleepybishop
sleepybishop marked this pull request as ready for review October 10, 2026 03:17
@BsAtHome

Copy link
Copy Markdown
Contributor

Same comment on the test as in #4660.

Comment on lines 193 to 197
r = hm2->llio->write(hm2->llio, hm2->bspi.instance[i].count_addr, &zero, sizeof(rtapi_u32));
if (r < 0) {
if (r <= 0) {
HM2_ERR("BSPI: hm2->llio->write failure %s\n", name);
return -1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llio->write() and llio->read() functions are supposed to return not zero on success and zero on failure.
From hostmot2-lowlevel.h:

    // on success these two return TRUE (not zero)
    // on failure they return FALSE (0) and set *self->io_error (below) to TRUE
    int (*read)(hm2_lowlevel_io_t *self, rtapi_u32 addr, void *buffer, int size);
    int (*write)(hm2_lowlevel_io_t *self, rtapi_u32 addr, const void *buffer, int size);

Any implementation that does not adhere to this should be fixed.

(same test other places as well)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 1ca33cf: zero means failure; nonzero means success.

Comment thread tests/hostmot2/serial/README Outdated
@@ -0,0 +1,23 @@
HostMot2 UART/BSPI and scan-rate software regression tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment on the test as with the pktuart code update.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the standalone harness and build hook.

Comment thread src/hal/drivers/mesa-hostmot2/uart.c Outdated
Comment on lines +216 to +219
buff = ((rtapi_u32)data[c]
| ((rtapi_u32)data[c+1] << 8)
| ((rtapi_u32)data[c+2] << 16)
| ((rtapi_u32)data[c+3] << 24));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the cast necessary?

(several more instances below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept only the cast before << 24: unsigned char promotes to signed int, so the cast makes that shift unsigned. Restored the original additions.

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.

2 participants