Skip to content

Commit

Permalink
Merge branch 'net-next-2024-12-03--21-00' into HEAD
Browse files Browse the repository at this point in the history
# Conflicts:
#	drivers/ptp/ptp_dte.c
#	drivers/ptp/ptp_ines.c
  • Loading branch information
Your Name committed Dec 3, 2024
2 parents 525b4ba + 5dfca34 commit 4a664b8
Show file tree
Hide file tree
Showing 183 changed files with 9,782 additions and 1,836 deletions.
58 changes: 58 additions & 0 deletions Documentation/core-api/packing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,61 @@ programmer against incorrect API use. The errors are not expected to occur
during runtime, therefore it is reasonable for xxx_packing() to return void
and simply swallow those errors. Optionally it can dump stack or print the
error description.

The pack_fields() and unpack_fields() macros automatically select the
appropriate function at compile time based on the type of the fields array
passed in.

Packed Fields
-------------

Drivers are encouraged to use the ``pack_fields()`` and ``unpack_fields()``
APIs over using ``pack()``, ``unpack()``, or ``packing()``.

These APIs use field definitions in arrays of ``struct packed_field_s`` or
``struct packed_field_m`` stored as ``.rodata``. This significantly reduces
the code footprint required to pack or unpack many fields. In addition,
sanity checks on the field definitions are handled at compile time with
``BUILD_BUG_ON`` rather than only when the offending code is executed.

It is recommended, but not required, that you wrap your packed buffer into a
structured type with a fixed size. This generally makes it easier for the
compiler to enforce that the correct size buffer is used.

Here is an example of how to use the fields APIs:

.. code-block:: c
struct data {
u64 field3;
u32 field4;
u16 field1;
u8 field2;
};
#define SIZE 13
typdef struct __packed { u8 buf[SIZE]; } packed_buf_t;
static const struct packed_field_s fields[] = {
PACKED_FIELD(100, 90, struct data, field1),
PACKED_FIELD(90, 87, struct data, field2),
PACKED_FIELD(86, 30, struct data, field3),
PACKED_FIELD(29, 0, struct data, field4),
};
void unpack_your_data(const packed_buf_t *buf, struct data *unpacked)
{
BUILD_BUG_ON(sizeof(*buf) != SIZE;
unpack_fields(buf, sizeof(*buf), unpacked, fields,
QUIRK_LITTLE_ENDIAN);
}
void pack_your_data(const struct data *unpacked, packed_buf_t *buf)
{
BUILD_BUG_ON(sizeof(*buf) != SIZE;
pack_fields(buf, sizeof(*buf), unpacked, fields,
QUIRK_LITTLE_ENDIAN);
}
2 changes: 1 addition & 1 deletion Documentation/netlink/genetlink-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ properties:
type: string
type: &attr-type
enum: [ unused, pad, flag, binary,
uint, sint, u8, u16, u32, u64, s32, s64,
uint, sint, u8, u16, u32, u64, s8, s16, s32, s64,
string, nest, indexed-array, nest-type-value ]
doc:
description: Documentation of the attribute.
Expand Down
5 changes: 4 additions & 1 deletion Documentation/netlink/genetlink-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ properties:
the right formatting mechanism when displaying values of this
type.
enum: [ hex, mac, fddi, ipv4, ipv6, uuid ]
struct:
description: Name of the nested struct type.
type: string
# End genetlink-legacy

attribute-sets:
Expand Down Expand Up @@ -200,7 +203,7 @@ properties:
type: &attr-type
description: The netlink attribute type
enum: [ unused, pad, flag, binary, bitfield32,
uint, sint, u8, u16, u32, u64, s32, s64,
uint, sint, u8, u16, u32, u64, s8, s16, s32, s64,
string, nest, indexed-array, nest-type-value ]
doc:
description: Documentation of the attribute.
Expand Down
2 changes: 1 addition & 1 deletion Documentation/netlink/genetlink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ properties:
type: string
type: &attr-type
enum: [ unused, pad, flag, binary,
uint, sint, u8, u16, u32, u64, s32, s64,
uint, sint, u8, u16, u32, u64, s8, s16, s32, s64,
string, nest, indexed-array, nest-type-value ]
doc:
description: Documentation of the attribute.
Expand Down
Loading

0 comments on commit 4a664b8

Please sign in to comment.