mirror of
https://github.com/torvalds/linux.git
synced 2024-11-27 14:41:39 +00:00
c0124f327e
The driver code qede_free_fp_array() depend on kfree() can be called with a NULL pointer. This stems from the qede_alloc_fp_array() function which either (kz)alloc memory for fp->txq or fp->rxq. This also simplifies error handling code in case of memory allocation failures, but xdp_rxq_info_unreg need to know the difference. Introduce xdp_rxq_info_is_reg() to handle if a memory allocation fails and detect this is the failure path by seeing that xdp_rxq_info was not registred yet, which first happens after successful alloaction in qede_init_fp(). Driver hook points for xdp_rxq_info: * reg : qede_init_fp * unreg: qede_free_fp_array Tested on actual hardware with samples/bpf program. V2: Driver have no proper error path for failed XDP RX-queue info reg, as qede_init_fp() is a void function. Cc: everest-linux-l2@cavium.com Cc: Ariel Elior <Ariel.Elior@cavium.com> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
74 lines
1.8 KiB
C
74 lines
1.8 KiB
C
/* net/core/xdp.c
|
|
*
|
|
* Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc.
|
|
* Released under terms in GPL version 2. See COPYING.
|
|
*/
|
|
#include <linux/types.h>
|
|
#include <linux/mm.h>
|
|
|
|
#include <net/xdp.h>
|
|
|
|
#define REG_STATE_NEW 0x0
|
|
#define REG_STATE_REGISTERED 0x1
|
|
#define REG_STATE_UNREGISTERED 0x2
|
|
#define REG_STATE_UNUSED 0x3
|
|
|
|
void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq)
|
|
{
|
|
/* Simplify driver cleanup code paths, allow unreg "unused" */
|
|
if (xdp_rxq->reg_state == REG_STATE_UNUSED)
|
|
return;
|
|
|
|
WARN(!(xdp_rxq->reg_state == REG_STATE_REGISTERED), "Driver BUG");
|
|
|
|
xdp_rxq->reg_state = REG_STATE_UNREGISTERED;
|
|
xdp_rxq->dev = NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_unreg);
|
|
|
|
static void xdp_rxq_info_init(struct xdp_rxq_info *xdp_rxq)
|
|
{
|
|
memset(xdp_rxq, 0, sizeof(*xdp_rxq));
|
|
}
|
|
|
|
/* Returns 0 on success, negative on failure */
|
|
int xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
|
|
struct net_device *dev, u32 queue_index)
|
|
{
|
|
if (xdp_rxq->reg_state == REG_STATE_UNUSED) {
|
|
WARN(1, "Driver promised not to register this");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (xdp_rxq->reg_state == REG_STATE_REGISTERED) {
|
|
WARN(1, "Missing unregister, handled but fix driver");
|
|
xdp_rxq_info_unreg(xdp_rxq);
|
|
}
|
|
|
|
if (!dev) {
|
|
WARN(1, "Missing net_device from driver");
|
|
return -ENODEV;
|
|
}
|
|
|
|
/* State either UNREGISTERED or NEW */
|
|
xdp_rxq_info_init(xdp_rxq);
|
|
xdp_rxq->dev = dev;
|
|
xdp_rxq->queue_index = queue_index;
|
|
|
|
xdp_rxq->reg_state = REG_STATE_REGISTERED;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_reg);
|
|
|
|
void xdp_rxq_info_unused(struct xdp_rxq_info *xdp_rxq)
|
|
{
|
|
xdp_rxq->reg_state = REG_STATE_UNUSED;
|
|
}
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_unused);
|
|
|
|
bool xdp_rxq_info_is_reg(struct xdp_rxq_info *xdp_rxq)
|
|
{
|
|
return (xdp_rxq->reg_state == REG_STATE_REGISTERED);
|
|
}
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_is_reg);
|