Skip to content

Conversation

@mhennerich
Copy link
Contributor

PR Description

Miscellaneous small fixes and updates

PR Type

  • [x ] Bug fix (a change that fixes an issue)

Initialize ret to 0 in jesd204_fsm_propagate_cb_top_level(). If num_links
is 0, the for loop never executes and ret would be returned uninitialized,
leading to undefined behavior.

Fixes: f72853d ("jesd204: rework the state machine for top-device propagation")

Signed-off-by: Michael Hennerich <[email protected]>
Add missing iter_idx++ in the list_for_each_entry loop when showing
output connection attributes. Without this increment, only index 0
would ever match, making sysfs attributes for output connections
beyond the first one inaccessible.

Fixes: 1080c2e ("jesd204: sysfs: add initial version for sysfs")

Signed-off-by: Michael Hennerich <[email protected]>
The str_cut_from_chr() function takes a character parameter 'c' but was
hardcoded to always search for '_' instead of using the passed parameter.
Fix by using strchr(s, c) instead of strchr(s, '_').

While all current callers pass '_', this fix ensures the function behaves
as its signature indicates and prevents bugs if future callers use a
different character.

Fixes: 1080c2e ("jesd204: sysfs: add initial version for sysfs")

Signed-off-by: Michael Hennerich <[email protected]>
The max variable was declared as 'int' but assigned 0xffffffff for
32-bit value validation, which overflows to -1 on most systems. This
caused the comparison 'val1 > max' to incorrectly reject valid values
when storing 32-bit attributes via sysfs.

Fix by:
- Changing max type from 'int' to 'u64' to hold all valid maximums
- Using U8_MAX, U16_MAX, U32_MAX macros for clarity and correctness
- Adding proper cast for kstrtoll() to avoid type mismatch warning

Fixes: 1080c2e ("jesd204: sysfs: add initial version for sysfs")

Signed-off-by: Michael Hennerich <[email protected]>
Add proper mutex serialization for FSM state transitions to prevent
concurrent access to FSM state data. This addresses the FIXME comment
in jesd204_fsm_table_single() about needing proper locking.

Changes:
- Add fsm_lock mutex to jesd204_dev_top structure
- Initialize mutex in jesd204_dev_alloc()
- Destroy mutex in jesd204_of_unregister_devices()
- Lock/unlock mutex around FSM table transitions in jesd204_fsm_table()
- Remove FIXME comment that was documenting this issue

This ensures thread-safe FSM operations when multiple contexts might
attempt state transitions simultaneously.

Signed-off-by: Michael Hennerich <[email protected]>
Add jesd204_dev_free_links() function to properly free dynamically
allocated lane_ids arrays when unregistering JESD204 devices. The
lane_ids are allocated in jesd204_dev_init_link_lane_ids() for both
active_links and staged_links, but were never freed on device removal.

The function only frees lane_ids that were dynamically allocated
(not provided statically via init_links) to avoid double-free issues.

Fixes: 34b513c ("jesd204: init JESD204 links info from driver")

Signed-off-by: Michael Hennerich <[email protected]>
Add validation in jesd204_dev_get_topology_top_dev() to detect and
warn when a JESD204 device is found in multiple topologies. This
addresses the FIXME comment about enforcing single-topology membership.

The function now iterates through all topologies to check for multiple
memberships, warns if detected, and returns the first topology found
for consistent behavior. This helps identify misconfigured device trees
where a device incorrectly spans multiple JESD204 topologies.

Signed-off-by: Michael Hennerich <[email protected]>
Add missing of_node_put() call when jesd204_dev_alloc() fails during
device tree node iteration. The for_each_node_with_property() macro
takes a reference on each node, which must be released when breaking
out of the loop early due to an error.

Fixes: 98086f3 ("jesd204: collect all devices on framework init")

Signed-off-by: Michael Hennerich <[email protected]>
Add defensive NULL check for jdev->dev_data before accessing state_ops
array in jesd204_fsm_table_entry_cb(). While dev_data should always be
set for registered devices, this check prevents potential NULL pointer
dereference if the FSM callback is invoked on a partially initialized
or corrupted device structure.

Signed-off-by: Michael Hennerich <[email protected]>
Add documentation comment explaining the purpose and value choice of
the EINVALID_STATE internal error code. This magic number is used to
signal FSM state validation failures and is intentionally chosen to be
outside the standard errno range to allow special handling during
state transitions and resume operations.

Signed-off-by: Michael Hennerich <[email protected]>
Add debug-level logging when FSM rollback operations are initiated.
This helps with debugging FSM state transition failures by logging
the source and target states during rollback, making it easier to
trace the sequence of state changes when errors occur.

Signed-off-by: Michael Hennerich <[email protected]>
Add kernel-doc documentation comments to the following functions that
were previously undocumented:

- jesd204_device_count_get(): Returns the count of registered devices
- jesd204_dev_get_topology_top_dev(): Finds top-level device for a topology
- jesd204_printk(): Prints kernel messages with JESD204 device context

These functions are part of the JESD204 framework API and benefit from
proper documentation for maintainability and developer reference.

Signed-off-by: Michael Hennerich <[email protected]>
Add the sample_rate_div member of struct jesd204_link to the sysfs
interface. This attribute was missing from the exported link parameters.

The sample_rate_div is an optional sample rate divider where the final
effective sample rate is calculated as: sample_rate / sample_rate_div.

The new attribute will appear as linkX_sample_rate_div in sysfs for
each JESD204 link.

Signed-off-by: Michael Hennerich <[email protected]>
@cseci
Copy link
Collaborator

cseci commented Dec 17, 2025

Linux Test Harness results now available here.

static char *str_cut_from_chr(char *s, char c)
{
char *ptr = strchr(s, '_');
char *ptr = strchr(s, c);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I would just argue about a fixes tag given that all callers use _

if (!jdev_top)
return -EFAULT;

mutex_lock(&jdev_top->fsm_lock);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we could use guard(mutex)...

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.

4 participants