[bug report] net/mlx5: Introduce inter-device communication mechanism

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Aviv Heller,

The patch fadd59fc50d0: "net/mlx5: Introduce inter-device
communication mechanism" from Dec 4, 2018, leads to the following
static checker warning:

	drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c:246 mlx5_devcom_get_peer_data()
	warn: potential off by one (named limit 'MLX5_MAX_PORTS') 'comp->device[i]'

drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
    226 void *mlx5_devcom_get_peer_data(struct mlx5_devcom *devcom,
    227 				enum mlx5_devcom_components id)
    228 {
    229 	struct mlx5_devcom_component *comp;
    230 	int i;
    231 
    232 	if (IS_ERR_OR_NULL(devcom))
    233 		return NULL;
    234 
    235 	comp = &devcom->priv->components[id];
    236 	down_read(&comp->sem);
    237 	if (!comp->paired) {
    238 		up_read(&comp->sem);
    239 		return NULL;
    240 	}
    241 
    242 	for (i = 0; i < MLX5_MAX_PORTS; i++)
    243 		if (i != devcom->idx)
                            ^^^^^^^^^^^^^^^^

    244 			break;
    245 
--> 246 	return comp->device[i].data;

Smatch thinks that "i" can be MLX5_MAX_PORTS but, of course, it can't.
I don't really understand the loop.  It's the equivalent of saying:

	return comp->device[(devcom->idx == 0) ? 1 : 0].data;

    247 }

regards,
dan carpenter



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux