Intel i40e code finds smatch bug
Dan McDonald <[email protected]>
| Newsgroups | org.kernel.vger.smatch |
|---|---|
| Message-ID | <[email protected]> |
We in illumos are in the midst of updating our i40e code from Intel upstream. We found a bug in smatch while building it. It's documented here in: https://www.illumos.org/issues/13457 A colleague recommended I include a toy program, try the smatch `master` branch on a Linux distro, and submit the toy to this list. Its source is attached, ready to compile (without incident) and smatch (with one incident, but not two). You'll see two cases of potential failure, but only one (the one Intel source uses to confirm proper compilation) breaks smatch. Look for the KEBE comments. Once this bug gets fixed, I suspect we'll also be updating our branch of smatch as well. :) Thanks, Dan
pack.c
(application/octet-stream, 1.6 KB)
#include <sys/types.h>
#include <inttypes.h>
#include <stdio.h>
#define u8 uint8_t
#define __le16 uint16_t
#define __le32 uint32_t
#pragma pack(1)
/* Run PHY Activity (0x0626) */
struct i40e_aqc_run_phy_activity {
u8 cmd_flags;
__le16 activity_id;
#define I40E_AQ_RUN_PHY_ACT_ID_USR_DFND 0x10
u8 reserved;
union {
struct {
__le32 dnl_opcode;
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT_DUR 0x801a
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT 0x801b
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_DUR 0x1801b
__le32 data;
u8 reserved2[4];
} cmd;
struct {
__le32 cmd_status;
#define I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC 0x4
#define I40E_AQ_RUN_PHY_ACT_CMD_STAT_MASK 0xFFFF
__le32 data0;
__le32 data1;
} resp;
} params;
};
#pragma pack()
#define I40E_CHECK_STRUCT_LEN(n, X) enum i40e_static_assert_enum_##X \
{ i40e_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
/* XXX KEBE SAYS this one fails! */
I40E_CHECK_STRUCT_LEN(16, i40e_aqc_run_phy_activity);
int
main(void)
{
struct i40e_aqc_run_phy_activity foo;
printf("foo == 0x%p, foo.activity_id = 0x%p, size == %d, tripval = %d\n",
&foo, &foo.activity_id, sizeof (struct i40e_aqc_run_phy_activity),
/* XXX KEBE SAYS but this one doesn't. */
16 / ((sizeof (struct i40e_aqc_run_phy_activity) == 16) ? 1 : 0) );
return (0);
}