* [net-next V7 PATCH 5/5] samples/bpf: add cpumap sample program xdp_redirect_cpu
From: Jesper Dangaard Brouer @ 2017-10-12 12:27 UTC (permalink / raw)
To: netdev
Cc: jakub.kicinski, Michael S. Tsirkin, pavel.odintsov, Jason Wang,
mchan, John Fastabend, peter.waskiewicz.jr,
Jesper Dangaard Brouer, ast, Daniel Borkmann, Alexei Starovoitov,
Andy Gospodarek
In-Reply-To: <150781116384.9409.2491501775270038284.stgit@firesoul>
This sample program show how to use cpumap and the associated
tracepoints.
It provides command line stats, which shows how the XDP-RX process,
cpumap-enqueue and cpumap kthread dequeue is cooperating on a per CPU
basis. It also utilize the xdp_exception and xdp_redirect_err
transpoints to allow users quickly to identify setup issues.
One issue with ixgbe driver is that the driver reset the link when
loading XDP. This reset the procfs smp_affinity settings. Thus,
after loading the program, these must be reconfigured. The easiest
workaround it to reduce the RX-queue to e.g. two via:
# ethtool --set-channels ixgbe1 combined 2
And then add CPUs above 0 and 1, like:
# xdp_redirect_cpu --dev ixgbe1 --prog 2 --cpu 2 --cpu 3 --cpu 4
Another issue with ixgbe is that the page recycle mechanism is tied to
the RX-ring size. And the default setting of 512 elements is too
small. This is the same issue with regular devmap XDP_REDIRECT.
To overcome this I've been using 1024 rx-ring size:
# ethtool -G ixgbe1 rx 1024 tx 1024
V3:
- whitespace cleanups
- bpf tracepoint cannot access top part of struct
V4:
- report on kthread sched events, according to tracepoint change
- report average bulk enqueue size
V5:
- bpf_map_lookup_elem on cpumap not allowed from bpf_prog
use separate map to mark CPUs not available
V6:
- correct kthread sched summary output
V7:
- Added a --stress-mode for concurrently changing underlying cpumap
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
samples/bpf/Makefile | 4
samples/bpf/xdp_redirect_cpu_kern.c | 609 +++++++++++++++++++++++++++++++
samples/bpf/xdp_redirect_cpu_user.c | 697 +++++++++++++++++++++++++++++++++++
3 files changed, 1310 insertions(+)
create mode 100644 samples/bpf/xdp_redirect_cpu_kern.c
create mode 100644 samples/bpf/xdp_redirect_cpu_user.c
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index ebc2ad69b62c..52c4dab2c153 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -39,6 +39,7 @@ hostprogs-y += per_socket_stats_example
hostprogs-y += load_sock_ops
hostprogs-y += xdp_redirect
hostprogs-y += xdp_redirect_map
+hostprogs-y += xdp_redirect_cpu
hostprogs-y += xdp_monitor
hostprogs-y += syscall_tp
@@ -84,6 +85,7 @@ test_map_in_map-objs := bpf_load.o $(LIBBPF) test_map_in_map_user.o
per_socket_stats_example-objs := $(LIBBPF) cookie_uid_helper_example.o
xdp_redirect-objs := bpf_load.o $(LIBBPF) xdp_redirect_user.o
xdp_redirect_map-objs := bpf_load.o $(LIBBPF) xdp_redirect_map_user.o
+xdp_redirect_cpu-objs := bpf_load.o $(LIBBPF) xdp_redirect_cpu_user.o
xdp_monitor-objs := bpf_load.o $(LIBBPF) xdp_monitor_user.o
syscall_tp-objs := bpf_load.o $(LIBBPF) syscall_tp_user.o
@@ -129,6 +131,7 @@ always += tcp_iw_kern.o
always += tcp_clamp_kern.o
always += xdp_redirect_kern.o
always += xdp_redirect_map_kern.o
+always += xdp_redirect_cpu_kern.o
always += xdp_monitor_kern.o
always += syscall_tp_kern.o
@@ -169,6 +172,7 @@ HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
HOSTLOADLIBES_test_map_in_map += -lelf
HOSTLOADLIBES_xdp_redirect += -lelf
HOSTLOADLIBES_xdp_redirect_map += -lelf
+HOSTLOADLIBES_xdp_redirect_cpu += -lelf
HOSTLOADLIBES_xdp_monitor += -lelf
HOSTLOADLIBES_syscall_tp += -lelf
diff --git a/samples/bpf/xdp_redirect_cpu_kern.c b/samples/bpf/xdp_redirect_cpu_kern.c
new file mode 100644
index 000000000000..303e9e7161f3
--- /dev/null
+++ b/samples/bpf/xdp_redirect_cpu_kern.c
@@ -0,0 +1,609 @@
+/* XDP redirect to CPUs via cpumap (BPF_MAP_TYPE_CPUMAP)
+ *
+ * GPLv2, Copyright(c) 2017 Jesper Dangaard Brouer, Red Hat, Inc.
+ */
+#include <uapi/linux/if_ether.h>
+#include <uapi/linux/if_packet.h>
+#include <uapi/linux/if_vlan.h>
+#include <uapi/linux/ip.h>
+#include <uapi/linux/ipv6.h>
+#include <uapi/linux/in.h>
+#include <uapi/linux/tcp.h>
+#include <uapi/linux/udp.h>
+
+#include <uapi/linux/bpf.h>
+#include "bpf_helpers.h"
+
+#define MAX_CPUS 12 /* WARNING - sync with _user.c */
+
+/* Special map type that can XDP_REDIRECT frames to another CPU */
+struct bpf_map_def SEC("maps") cpu_map = {
+ .type = BPF_MAP_TYPE_CPUMAP,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(u32),
+ .max_entries = MAX_CPUS,
+};
+
+/* Common stats data record to keep userspace more simple */
+struct datarec {
+ __u64 processed;
+ __u64 dropped;
+ __u64 issue;
+};
+
+/* Count RX packets, as XDP bpf_prog doesn't get direct TX-success
+ * feedback. Redirect TX errors can be caught via a tracepoint.
+ */
+struct bpf_map_def SEC("maps") rx_cnt = {
+ .type = BPF_MAP_TYPE_PERCPU_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(struct datarec),
+ .max_entries = 1,
+};
+
+/* Used by trace point */
+struct bpf_map_def SEC("maps") redirect_err_cnt = {
+ .type = BPF_MAP_TYPE_PERCPU_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(struct datarec),
+ .max_entries = 2,
+ /* TODO: have entries for all possible errno's */
+};
+
+/* Used by trace point */
+struct bpf_map_def SEC("maps") cpumap_enqueue_cnt = {
+ .type = BPF_MAP_TYPE_PERCPU_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(struct datarec),
+ .max_entries = MAX_CPUS,
+};
+
+/* Used by trace point */
+struct bpf_map_def SEC("maps") cpumap_kthread_cnt = {
+ .type = BPF_MAP_TYPE_PERCPU_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(struct datarec),
+ .max_entries = 1,
+};
+
+/* Set of maps controlling available CPU, and for iterating through
+ * selectable redirect CPUs.
+ */
+struct bpf_map_def SEC("maps") cpus_available = {
+ .type = BPF_MAP_TYPE_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(u32),
+ .max_entries = MAX_CPUS,
+};
+struct bpf_map_def SEC("maps") cpus_count = {
+ .type = BPF_MAP_TYPE_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(u32),
+ .max_entries = 1,
+};
+struct bpf_map_def SEC("maps") cpus_iterator = {
+ .type = BPF_MAP_TYPE_PERCPU_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(u32),
+ .max_entries = 1,
+};
+
+/* Used by trace point */
+struct bpf_map_def SEC("maps") exception_cnt = {
+ .type = BPF_MAP_TYPE_PERCPU_ARRAY,
+ .key_size = sizeof(u32),
+ .value_size = sizeof(struct datarec),
+ .max_entries = 1,
+};
+
+/* Helper parse functions */
+
+/* Parse Ethernet layer 2, extract network layer 3 offset and protocol
+ *
+ * Returns false on error and non-supported ether-type
+ */
+struct vlan_hdr {
+ __be16 h_vlan_TCI;
+ __be16 h_vlan_encapsulated_proto;
+};
+
+static __always_inline
+bool parse_eth(struct ethhdr *eth, void *data_end,
+ u16 *eth_proto, u64 *l3_offset)
+{
+ u16 eth_type;
+ u64 offset;
+
+ offset = sizeof(*eth);
+ if ((void *)eth + offset > data_end)
+ return false;
+
+ eth_type = eth->h_proto;
+
+ /* Skip non 802.3 Ethertypes */
+ if (unlikely(ntohs(eth_type) < ETH_P_802_3_MIN))
+ return false;
+
+ /* Handle VLAN tagged packet */
+ if (eth_type == htons(ETH_P_8021Q) || eth_type == htons(ETH_P_8021AD)) {
+ struct vlan_hdr *vlan_hdr;
+
+ vlan_hdr = (void *)eth + offset;
+ offset += sizeof(*vlan_hdr);
+ if ((void *)eth + offset > data_end)
+ return false;
+ eth_type = vlan_hdr->h_vlan_encapsulated_proto;
+ }
+ /* TODO: Handle double VLAN tagged packet */
+
+ *eth_proto = ntohs(eth_type);
+ *l3_offset = offset;
+ return true;
+}
+
+static __always_inline
+u16 get_dest_port_ipv4_udp(struct xdp_md *ctx, u64 nh_off)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct iphdr *iph = data + nh_off;
+ struct udphdr *udph;
+ u16 dport;
+
+ if (iph + 1 > data_end)
+ return 0;
+ if (!(iph->protocol == IPPROTO_UDP))
+ return 0;
+
+ udph = (void *)(iph + 1);
+ if (udph + 1 > data_end)
+ return 0;
+
+ dport = ntohs(udph->dest);
+ return dport;
+}
+
+static __always_inline
+int get_proto_ipv4(struct xdp_md *ctx, u64 nh_off)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct iphdr *iph = data + nh_off;
+
+ if (iph + 1 > data_end)
+ return 0;
+ return iph->protocol;
+}
+
+static __always_inline
+int get_proto_ipv6(struct xdp_md *ctx, u64 nh_off)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct ipv6hdr *ip6h = data + nh_off;
+
+ if (ip6h + 1 > data_end)
+ return 0;
+ return ip6h->nexthdr;
+}
+
+SEC("xdp_cpu_map0")
+int xdp_prognum0_no_touch(struct xdp_md *ctx)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct datarec *rec;
+ u32 *cpu_selected;
+ u32 cpu_dest;
+ u32 key = 0;
+
+ /* Only use first entry in cpus_available */
+ cpu_selected = bpf_map_lookup_elem(&cpus_available, &key);
+ if (!cpu_selected)
+ return XDP_ABORTED;
+ cpu_dest = *cpu_selected;
+
+ /* Count RX packet in map */
+ rec = bpf_map_lookup_elem(&rx_cnt, &key);
+ if (!rec)
+ return XDP_ABORTED;
+ rec->processed++;
+
+ if (cpu_dest >= MAX_CPUS) {
+ rec->issue++;
+ return XDP_ABORTED;
+ }
+
+ return bpf_redirect_map(&cpu_map, cpu_dest, 0);
+}
+
+SEC("xdp_cpu_map1_touch_data")
+int xdp_prognum1_touch_data(struct xdp_md *ctx)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct ethhdr *eth = data;
+ struct datarec *rec;
+ u32 *cpu_selected;
+ u32 cpu_dest;
+ u16 eth_type;
+ u32 key = 0;
+
+ /* Only use first entry in cpus_available */
+ cpu_selected = bpf_map_lookup_elem(&cpus_available, &key);
+ if (!cpu_selected)
+ return XDP_ABORTED;
+ cpu_dest = *cpu_selected;
+
+ /* Validate packet length is minimum Eth header size */
+ if (eth + 1 > data_end)
+ return XDP_ABORTED;
+
+ /* Count RX packet in map */
+ rec = bpf_map_lookup_elem(&rx_cnt, &key);
+ if (!rec)
+ return XDP_ABORTED;
+ rec->processed++;
+
+ /* Read packet data, and use it (drop non 802.3 Ethertypes) */
+ eth_type = eth->h_proto;
+ if (ntohs(eth_type) < ETH_P_802_3_MIN) {
+ rec->dropped++;
+ return XDP_DROP;
+ }
+
+ if (cpu_dest >= MAX_CPUS) {
+ rec->issue++;
+ return XDP_ABORTED;
+ }
+
+ return bpf_redirect_map(&cpu_map, cpu_dest, 0);
+}
+
+SEC("xdp_cpu_map2_round_robin")
+int xdp_prognum2_round_robin(struct xdp_md *ctx)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct ethhdr *eth = data;
+ struct datarec *rec;
+ u32 cpu_dest;
+ u32 *cpu_lookup;
+ u32 key0 = 0;
+
+ u32 *cpu_selected;
+ u32 *cpu_iterator;
+ u32 *cpu_max;
+ u32 cpu_idx;
+
+ cpu_max = bpf_map_lookup_elem(&cpus_count, &key0);
+ if (!cpu_max)
+ return XDP_ABORTED;
+
+ cpu_iterator = bpf_map_lookup_elem(&cpus_iterator, &key0);
+ if (!cpu_iterator)
+ return XDP_ABORTED;
+ cpu_idx = *cpu_iterator;
+
+ *cpu_iterator += 1;
+ if (*cpu_iterator == *cpu_max)
+ *cpu_iterator = 0;
+
+ cpu_selected = bpf_map_lookup_elem(&cpus_available, &cpu_idx);
+ if (!cpu_selected)
+ return XDP_ABORTED;
+ cpu_dest = *cpu_selected;
+
+ /* Count RX packet in map */
+ rec = bpf_map_lookup_elem(&rx_cnt, &key0);
+ if (!rec)
+ return XDP_ABORTED;
+ rec->processed++;
+
+ if (cpu_dest >= MAX_CPUS) {
+ rec->issue++;
+ return XDP_ABORTED;
+ }
+
+ return bpf_redirect_map(&cpu_map, cpu_dest, 0);
+}
+
+SEC("xdp_cpu_map3_proto_separate")
+int xdp_prognum3_proto_separate(struct xdp_md *ctx)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct ethhdr *eth = data;
+ u8 ip_proto = IPPROTO_UDP;
+ struct datarec *rec;
+ u16 eth_proto = 0;
+ u64 l3_offset = 0;
+ u32 cpu_dest = 0;
+ u32 cpu_idx = 0;
+ u32 *cpu_lookup;
+ u32 key = 0;
+
+ /* Count RX packet in map */
+ rec = bpf_map_lookup_elem(&rx_cnt, &key);
+ if (!rec)
+ return XDP_ABORTED;
+ rec->processed++;
+
+ if (!(parse_eth(eth, data_end, ð_proto, &l3_offset)))
+ return XDP_PASS; /* Just skip */
+
+ /* Extract L4 protocol */
+ switch (eth_proto) {
+ case ETH_P_IP:
+ ip_proto = get_proto_ipv4(ctx, l3_offset);
+ break;
+ case ETH_P_IPV6:
+ ip_proto = get_proto_ipv6(ctx, l3_offset);
+ break;
+ case ETH_P_ARP:
+ cpu_idx = 0; /* ARP packet handled on separate CPU */
+ break;
+ default:
+ cpu_idx = 0;
+ }
+
+ /* Choose CPU based on L4 protocol */
+ switch (ip_proto) {
+ case IPPROTO_ICMP:
+ case IPPROTO_ICMPV6:
+ cpu_idx = 2;
+ break;
+ case IPPROTO_TCP:
+ cpu_idx = 0;
+ break;
+ case IPPROTO_UDP:
+ cpu_idx = 1;
+ break;
+ default:
+ cpu_idx = 0;
+ }
+
+ cpu_lookup = bpf_map_lookup_elem(&cpus_available, &cpu_idx);
+ if (!cpu_lookup)
+ return XDP_ABORTED;
+ cpu_dest = *cpu_lookup;
+
+ if (cpu_dest >= MAX_CPUS) {
+ rec->issue++;
+ return XDP_ABORTED;
+ }
+
+ return bpf_redirect_map(&cpu_map, cpu_dest, 0);
+}
+
+SEC("xdp_cpu_map4_ddos_filter_pktgen")
+int xdp_prognum4_ddos_filter_pktgen(struct xdp_md *ctx)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct ethhdr *eth = data;
+ u8 ip_proto = IPPROTO_UDP;
+ struct datarec *rec;
+ u16 eth_proto = 0;
+ u64 l3_offset = 0;
+ u32 cpu_dest = 0;
+ u32 cpu_idx = 0;
+ u16 dest_port;
+ u32 *cpu_lookup;
+ u32 key = 0;
+
+ /* Count RX packet in map */
+ rec = bpf_map_lookup_elem(&rx_cnt, &key);
+ if (!rec)
+ return XDP_ABORTED;
+ rec->processed++;
+
+ if (!(parse_eth(eth, data_end, ð_proto, &l3_offset)))
+ return XDP_PASS; /* Just skip */
+
+ /* Extract L4 protocol */
+ switch (eth_proto) {
+ case ETH_P_IP:
+ ip_proto = get_proto_ipv4(ctx, l3_offset);
+ break;
+ case ETH_P_IPV6:
+ ip_proto = get_proto_ipv6(ctx, l3_offset);
+ break;
+ case ETH_P_ARP:
+ cpu_idx = 0; /* ARP packet handled on separate CPU */
+ break;
+ default:
+ cpu_idx = 0;
+ }
+
+ /* Choose CPU based on L4 protocol */
+ switch (ip_proto) {
+ case IPPROTO_ICMP:
+ case IPPROTO_ICMPV6:
+ cpu_idx = 2;
+ break;
+ case IPPROTO_TCP:
+ cpu_idx = 0;
+ break;
+ case IPPROTO_UDP:
+ cpu_idx = 1;
+ /* DDoS filter UDP port 9 (pktgen) */
+ dest_port = get_dest_port_ipv4_udp(ctx, l3_offset);
+ if (dest_port == 9) {
+ if (rec)
+ rec->dropped++;
+ return XDP_DROP;
+ }
+ break;
+ default:
+ cpu_idx = 0;
+ }
+
+ cpu_lookup = bpf_map_lookup_elem(&cpus_available, &cpu_idx);
+ if (!cpu_lookup)
+ return XDP_ABORTED;
+ cpu_dest = *cpu_lookup;
+
+ if (cpu_dest >= MAX_CPUS) {
+ rec->issue++;
+ return XDP_ABORTED;
+ }
+
+ return bpf_redirect_map(&cpu_map, cpu_dest, 0);
+}
+
+
+char _license[] SEC("license") = "GPL";
+
+/*** Trace point code ***/
+
+/* Tracepoint format: /sys/kernel/debug/tracing/events/xdp/xdp_redirect/format
+ * Code in: kernel/include/trace/events/xdp.h
+ */
+struct xdp_redirect_ctx {
+ u64 __pad; // First 8 bytes are not accessible by bpf code
+ int prog_id; // offset:8; size:4; signed:1;
+ u32 act; // offset:12 size:4; signed:0;
+ int ifindex; // offset:16 size:4; signed:1;
+ int err; // offset:20 size:4; signed:1;
+ int to_ifindex; // offset:24 size:4; signed:1;
+ u32 map_id; // offset:28 size:4; signed:0;
+ int map_index; // offset:32 size:4; signed:1;
+}; // offset:36
+
+enum {
+ XDP_REDIRECT_SUCCESS = 0,
+ XDP_REDIRECT_ERROR = 1
+};
+
+static __always_inline
+int xdp_redirect_collect_stat(struct xdp_redirect_ctx *ctx)
+{
+ u32 key = XDP_REDIRECT_ERROR;
+ struct datarec *rec;
+ int err = ctx->err;
+
+ if (!err)
+ key = XDP_REDIRECT_SUCCESS;
+
+ rec = bpf_map_lookup_elem(&redirect_err_cnt, &key);
+ if (!rec)
+ return 0;
+ rec->dropped += 1;
+
+ return 0; /* Indicate event was filtered (no further processing)*/
+ /*
+ * Returning 1 here would allow e.g. a perf-record tracepoint
+ * to see and record these events, but it doesn't work well
+ * in-practice as stopping perf-record also unload this
+ * bpf_prog. Plus, there is additional overhead of doing so.
+ */
+}
+
+SEC("tracepoint/xdp/xdp_redirect_err")
+int trace_xdp_redirect_err(struct xdp_redirect_ctx *ctx)
+{
+ return xdp_redirect_collect_stat(ctx);
+}
+
+SEC("tracepoint/xdp/xdp_redirect_map_err")
+int trace_xdp_redirect_map_err(struct xdp_redirect_ctx *ctx)
+{
+ return xdp_redirect_collect_stat(ctx);
+}
+
+/* Tracepoint format: /sys/kernel/debug/tracing/events/xdp/xdp_exception/format
+ * Code in: kernel/include/trace/events/xdp.h
+ */
+struct xdp_exception_ctx {
+ u64 __pad; // First 8 bytes are not accessible by bpf code
+ int prog_id; // offset:8; size:4; signed:1;
+ u32 act; // offset:12; size:4; signed:0;
+ int ifindex; // offset:16; size:4; signed:1;
+};
+
+SEC("tracepoint/xdp/xdp_exception")
+int trace_xdp_exception(struct xdp_exception_ctx *ctx)
+{
+ struct datarec *rec;
+ u32 key = 0;
+
+ rec = bpf_map_lookup_elem(&exception_cnt, &key);
+ if (!rec)
+ return 1;
+ rec->dropped += 1;
+
+ return 0;
+}
+
+/* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_cpumap_enqueue/format
+ * Code in: kernel/include/trace/events/xdp.h
+ */
+struct cpumap_enqueue_ctx {
+ u64 __pad; // First 8 bytes are not accessible by bpf code
+ int map_id; // offset:8; size:4; signed:1;
+ u32 act; // offset:12; size:4; signed:0;
+ int cpu; // offset:16; size:4; signed:1;
+ unsigned int drops; // offset:20; size:4; signed:0;
+ unsigned int processed; // offset:24; size:4; signed:0;
+ int to_cpu; // offset:28; size:4; signed:1;
+};
+
+SEC("tracepoint/xdp/xdp_cpumap_enqueue")
+int trace_xdp_cpumap_enqueue(struct cpumap_enqueue_ctx *ctx)
+{
+ u32 to_cpu = ctx->to_cpu;
+ struct datarec *rec;
+
+ if (to_cpu >= MAX_CPUS)
+ return 1;
+
+ rec = bpf_map_lookup_elem(&cpumap_enqueue_cnt, &to_cpu);
+ if (!rec)
+ return 0;
+ rec->processed += ctx->processed;
+ rec->dropped += ctx->drops;
+
+ /* Record bulk events, then userspace can calc average bulk size */
+ if (ctx->processed > 0)
+ rec->issue += 1;
+
+ /* Inception: It's possible to detect overload situations, via
+ * this tracepoint. This can be used for creating a feedback
+ * loop to XDP, which can take appropriate actions to mitigate
+ * this overload situation.
+ */
+ return 0;
+}
+
+/* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_cpumap_kthread/format
+ * Code in: kernel/include/trace/events/xdp.h
+ */
+struct cpumap_kthread_ctx {
+ u64 __pad; // First 8 bytes are not accessible by bpf code
+ int map_id; // offset:8; size:4; signed:1;
+ u32 act; // offset:12; size:4; signed:0;
+ int cpu; // offset:16; size:4; signed:1;
+ unsigned int drops; // offset:20; size:4; signed:0;
+ unsigned int processed; // offset:24; size:4; signed:0;
+ int sched; // offset:28; size:4; signed:1;
+};
+
+SEC("tracepoint/xdp/xdp_cpumap_kthread")
+int trace_xdp_cpumap_kthread(struct cpumap_kthread_ctx *ctx)
+{
+ struct datarec *rec;
+ u32 key = 0;
+
+ rec = bpf_map_lookup_elem(&cpumap_kthread_cnt, &key);
+ if (!rec)
+ return 0;
+ rec->processed += ctx->processed;
+ rec->dropped += ctx->drops;
+
+ /* Count times kthread yielded CPU via schedule call */
+ if (ctx->sched)
+ rec->issue++;
+
+ return 0;
+}
diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c
new file mode 100644
index 000000000000..35fec9fecb57
--- /dev/null
+++ b/samples/bpf/xdp_redirect_cpu_user.c
@@ -0,0 +1,697 @@
+/* GPLv2 Copyright(c) 2017 Jesper Dangaard Brouer, Red Hat, Inc.
+ */
+static const char *__doc__ =
+ " XDP redirect with a CPU-map type \"BPF_MAP_TYPE_CPUMAP\"";
+
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <locale.h>
+#include <sys/resource.h>
+#include <getopt.h>
+#include <net/if.h>
+#include <time.h>
+
+#include <arpa/inet.h>
+#include <linux/if_link.h>
+
+#define MAX_CPUS 12 /* WARNING - sync with _kern.c */
+
+/* How many xdp_progs are defined in _kern.c */
+#define MAX_PROG 5
+
+/* Wanted to get rid of bpf_load.h and fake-"libbpf.h" (and instead
+ * use bpf/libbpf.h), but cannot as (currently) needed for XDP
+ * attaching to a device via set_link_xdp_fd()
+ */
+#include "libbpf.h"
+#include "bpf_load.h"
+
+#include "bpf_util.h"
+
+static int ifindex = -1;
+static char ifname_buf[IF_NAMESIZE];
+static char *ifname;
+
+static __u32 xdp_flags;
+
+/* Exit return codes */
+#define EXIT_OK 0
+#define EXIT_FAIL 1
+#define EXIT_FAIL_OPTION 2
+#define EXIT_FAIL_XDP 3
+#define EXIT_FAIL_BPF 4
+#define EXIT_FAIL_MEM 5
+
+static const struct option long_options[] = {
+ {"help", no_argument, NULL, 'h' },
+ {"dev", required_argument, NULL, 'd' },
+ {"skb-mode", no_argument, NULL, 'S' },
+ {"debug", no_argument, NULL, 'D' },
+ {"sec", required_argument, NULL, 's' },
+ {"prognum", required_argument, NULL, 'p' },
+ {"qsize", required_argument, NULL, 'q' },
+ {"cpu", required_argument, NULL, 'c' },
+ {"stress-mode", no_argument, NULL, 'x' },
+ {"no-separators", no_argument, NULL, 'z' },
+ {0, 0, NULL, 0 }
+};
+
+static void int_exit(int sig)
+{
+ fprintf(stderr,
+ "Interrupted: Removing XDP program on ifindex:%d device:%s\n",
+ ifindex, ifname);
+ if (ifindex > -1)
+ set_link_xdp_fd(ifindex, -1, xdp_flags);
+ exit(EXIT_OK);
+}
+
+static void usage(char *argv[])
+{
+ int i;
+
+ printf("\nDOCUMENTATION:\n%s\n", __doc__);
+ printf("\n");
+ printf(" Usage: %s (options-see-below)\n", argv[0]);
+ printf(" Listing options:\n");
+ for (i = 0; long_options[i].name != 0; i++) {
+ printf(" --%-12s", long_options[i].name);
+ if (long_options[i].flag != NULL)
+ printf(" flag (internal value:%d)",
+ *long_options[i].flag);
+ else
+ printf(" short-option: -%c",
+ long_options[i].val);
+ printf("\n");
+ }
+ printf("\n");
+}
+
+/* gettime returns the current time of day in nanoseconds.
+ * Cost: clock_gettime (ns) => 26ns (CLOCK_MONOTONIC)
+ * clock_gettime (ns) => 9ns (CLOCK_MONOTONIC_COARSE)
+ */
+#define NANOSEC_PER_SEC 1000000000 /* 10^9 */
+static __u64 gettime(void)
+{
+ struct timespec t;
+ int res;
+
+ res = clock_gettime(CLOCK_MONOTONIC, &t);
+ if (res < 0) {
+ fprintf(stderr, "Error with gettimeofday! (%i)\n", res);
+ exit(EXIT_FAIL);
+ }
+ return (__u64) t.tv_sec * NANOSEC_PER_SEC + t.tv_nsec;
+}
+
+/* Common stats data record shared with _kern.c */
+struct datarec {
+ __u64 processed;
+ __u64 dropped;
+ __u64 issue;
+};
+struct record {
+ __u64 timestamp;
+ struct datarec total;
+ struct datarec *cpu;
+};
+struct stats_record {
+ struct record rx_cnt;
+ struct record redir_err;
+ struct record kthread;
+ struct record exception;
+ struct record enq[MAX_CPUS];
+};
+
+static bool map_collect_percpu(int fd, __u32 key, struct record *rec)
+{
+ /* For percpu maps, userspace gets a value per possible CPU */
+ unsigned int nr_cpus = bpf_num_possible_cpus();
+ struct datarec values[nr_cpus];
+ __u64 sum_processed = 0;
+ __u64 sum_dropped = 0;
+ __u64 sum_issue = 0;
+ int i;
+
+ if ((bpf_map_lookup_elem(fd, &key, values)) != 0) {
+ fprintf(stderr,
+ "ERR: bpf_map_lookup_elem failed key:0x%X\n", key);
+ return false;
+ }
+ /* Get time as close as possible to reading map contents */
+ rec->timestamp = gettime();
+
+ /* Record and sum values from each CPU */
+ for (i = 0; i < nr_cpus; i++) {
+ rec->cpu[i].processed = values[i].processed;
+ sum_processed += values[i].processed;
+ rec->cpu[i].dropped = values[i].dropped;
+ sum_dropped += values[i].dropped;
+ rec->cpu[i].issue = values[i].issue;
+ sum_issue += values[i].issue;
+ }
+ rec->total.processed = sum_processed;
+ rec->total.dropped = sum_dropped;
+ rec->total.issue = sum_issue;
+ return true;
+}
+
+static struct datarec *alloc_record_per_cpu(void)
+{
+ unsigned int nr_cpus = bpf_num_possible_cpus();
+ struct datarec *array;
+ size_t size;
+
+ size = sizeof(struct datarec) * nr_cpus;
+ array = malloc(size);
+ memset(array, 0, size);
+ if (!array) {
+ fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
+ exit(EXIT_FAIL_MEM);
+ }
+ return array;
+}
+
+static struct stats_record *alloc_stats_record(void)
+{
+ struct stats_record *rec;
+ int i;
+
+ rec = malloc(sizeof(*rec));
+ memset(rec, 0, sizeof(*rec));
+ if (!rec) {
+ fprintf(stderr, "Mem alloc error\n");
+ exit(EXIT_FAIL_MEM);
+ }
+ rec->rx_cnt.cpu = alloc_record_per_cpu();
+ rec->redir_err.cpu = alloc_record_per_cpu();
+ rec->kthread.cpu = alloc_record_per_cpu();
+ rec->exception.cpu = alloc_record_per_cpu();
+ for (i = 0; i < MAX_CPUS; i++)
+ rec->enq[i].cpu = alloc_record_per_cpu();
+
+ return rec;
+}
+
+static void free_stats_record(struct stats_record *r)
+{
+ int i;
+
+ for (i = 0; i < MAX_CPUS; i++)
+ free(r->enq[i].cpu);
+ free(r->exception.cpu);
+ free(r->kthread.cpu);
+ free(r->redir_err.cpu);
+ free(r->rx_cnt.cpu);
+ free(r);
+}
+
+static double calc_period(struct record *r, struct record *p)
+{
+ double period_ = 0;
+ __u64 period = 0;
+
+ period = r->timestamp - p->timestamp;
+ if (period > 0)
+ period_ = ((double) period / NANOSEC_PER_SEC);
+
+ return period_;
+}
+
+static __u64 calc_pps(struct datarec *r, struct datarec *p, double period_)
+{
+ __u64 packets = 0;
+ __u64 pps = 0;
+
+ if (period_ > 0) {
+ packets = r->processed - p->processed;
+ pps = packets / period_;
+ }
+ return pps;
+}
+
+static __u64 calc_drop_pps(struct datarec *r, struct datarec *p, double period_)
+{
+ __u64 packets = 0;
+ __u64 pps = 0;
+
+ if (period_ > 0) {
+ packets = r->dropped - p->dropped;
+ pps = packets / period_;
+ }
+ return pps;
+}
+
+static __u64 calc_errs_pps(struct datarec *r,
+ struct datarec *p, double period_)
+{
+ __u64 packets = 0;
+ __u64 pps = 0;
+
+ if (period_ > 0) {
+ packets = r->issue - p->issue;
+ pps = packets / period_;
+ }
+ return pps;
+}
+
+static void stats_print(struct stats_record *stats_rec,
+ struct stats_record *stats_prev,
+ int prog_num)
+{
+ unsigned int nr_cpus = bpf_num_possible_cpus();
+ double pps = 0, drop = 0, err = 0;
+ struct record *rec, *prev;
+ int to_cpu;
+ double t;
+ int i;
+
+ /* Header */
+ printf("Running XDP/eBPF prog_num:%d\n", prog_num);
+ printf("%-15s %-7s %-14s %-11s %-9s\n",
+ "XDP-cpumap", "CPU:to", "pps", "drop-pps", "extra-info");
+
+ /* XDP rx_cnt */
+ {
+ char *fmt_rx = "%-15s %-7d %'-14.0f %'-11.0f %'-10.0f %s\n";
+ char *fm2_rx = "%-15s %-7s %'-14.0f %'-11.0f\n";
+ char *errstr = "";
+
+ rec = &stats_rec->rx_cnt;
+ prev = &stats_prev->rx_cnt;
+ t = calc_period(rec, prev);
+ for (i = 0; i < nr_cpus; i++) {
+ struct datarec *r = &rec->cpu[i];
+ struct datarec *p = &prev->cpu[i];
+
+ pps = calc_pps(r, p, t);
+ drop = calc_drop_pps(r, p, t);
+ err = calc_errs_pps(r, p, t);
+ if (err > 0)
+ errstr = "cpu-dest/err";
+ if (pps > 0)
+ printf(fmt_rx, "XDP-RX",
+ i, pps, drop, err, errstr);
+ }
+ pps = calc_pps(&rec->total, &prev->total, t);
+ drop = calc_drop_pps(&rec->total, &prev->total, t);
+ err = calc_errs_pps(&rec->total, &prev->total, t);
+ printf(fm2_rx, "XDP-RX", "total", pps, drop);
+ }
+
+ /* cpumap enqueue stats */
+ for (to_cpu = 0; to_cpu < MAX_CPUS; to_cpu++) {
+ char *fmt = "%-15s %3d:%-3d %'-14.0f %'-11.0f %'-10.2f %s\n";
+ char *fm2 = "%-15s %3s:%-3d %'-14.0f %'-11.0f %'-10.2f %s\n";
+ char *errstr = "";
+
+ rec = &stats_rec->enq[to_cpu];
+ prev = &stats_prev->enq[to_cpu];
+ t = calc_period(rec, prev);
+ for (i = 0; i < nr_cpus; i++) {
+ struct datarec *r = &rec->cpu[i];
+ struct datarec *p = &prev->cpu[i];
+
+ pps = calc_pps(r, p, t);
+ drop = calc_drop_pps(r, p, t);
+ err = calc_errs_pps(r, p, t);
+ if (err > 0) {
+ errstr = "bulk-average";
+ err = pps / err; /* calc average bulk size */
+ }
+ if (pps > 0)
+ printf(fmt, "cpumap-enqueue",
+ i, to_cpu, pps, drop, err, errstr);
+ }
+ pps = calc_pps(&rec->total, &prev->total, t);
+ if (pps > 0) {
+ drop = calc_drop_pps(&rec->total, &prev->total, t);
+ err = calc_errs_pps(&rec->total, &prev->total, t);
+ if (err > 0) {
+ errstr = "bulk-average";
+ err = pps / err; /* calc average bulk size */
+ }
+ printf(fm2, "cpumap-enqueue",
+ "sum", to_cpu, pps, drop, err, errstr);
+ }
+ }
+
+ /* cpumap kthread stats */
+ {
+ char *fmt_k = "%-15s %-7d %'-14.0f %'-11.0f %'-10.0f %s\n";
+ char *fm2_k = "%-15s %-7s %'-14.0f %'-11.0f %'-10.0f %s\n";
+ char *e_str = "";
+
+ rec = &stats_rec->kthread;
+ prev = &stats_prev->kthread;
+ t = calc_period(rec, prev);
+ for (i = 0; i < nr_cpus; i++) {
+ struct datarec *r = &rec->cpu[i];
+ struct datarec *p = &prev->cpu[i];
+
+ pps = calc_pps(r, p, t);
+ drop = calc_drop_pps(r, p, t);
+ err = calc_errs_pps(r, p, t);
+ if (err > 0)
+ e_str = "sched";
+ if (pps > 0)
+ printf(fmt_k, "cpumap_kthread",
+ i, pps, drop, err, e_str);
+ }
+ pps = calc_pps(&rec->total, &prev->total, t);
+ drop = calc_drop_pps(&rec->total, &prev->total, t);
+ err = calc_errs_pps(&rec->total, &prev->total, t);
+ if (err > 0)
+ e_str = "sched-sum";
+ printf(fm2_k, "cpumap_kthread", "total", pps, drop, err, e_str);
+ }
+
+ /* XDP redirect err tracepoints (very unlikely) */
+ {
+ char *fmt_err = "%-15s %-7d %'-14.0f %'-11.0f\n";
+ char *fm2_err = "%-15s %-7s %'-14.0f %'-11.0f\n";
+
+ rec = &stats_rec->redir_err;
+ prev = &stats_prev->redir_err;
+ t = calc_period(rec, prev);
+ for (i = 0; i < nr_cpus; i++) {
+ struct datarec *r = &rec->cpu[i];
+ struct datarec *p = &prev->cpu[i];
+
+ pps = calc_pps(r, p, t);
+ drop = calc_drop_pps(r, p, t);
+ if (pps > 0)
+ printf(fmt_err, "redirect_err", i, pps, drop);
+ }
+ pps = calc_pps(&rec->total, &prev->total, t);
+ drop = calc_drop_pps(&rec->total, &prev->total, t);
+ printf(fm2_err, "redirect_err", "total", pps, drop);
+ }
+
+ /* XDP general exception tracepoints */
+ {
+ char *fmt_err = "%-15s %-7d %'-14.0f %'-11.0f\n";
+ char *fm2_err = "%-15s %-7s %'-14.0f %'-11.0f\n";
+
+ rec = &stats_rec->exception;
+ prev = &stats_prev->exception;
+ t = calc_period(rec, prev);
+ for (i = 0; i < nr_cpus; i++) {
+ struct datarec *r = &rec->cpu[i];
+ struct datarec *p = &prev->cpu[i];
+
+ pps = calc_pps(r, p, t);
+ drop = calc_drop_pps(r, p, t);
+ if (pps > 0)
+ printf(fmt_err, "xdp_exception", i, pps, drop);
+ }
+ pps = calc_pps(&rec->total, &prev->total, t);
+ drop = calc_drop_pps(&rec->total, &prev->total, t);
+ printf(fm2_err, "xdp_exception", "total", pps, drop);
+ }
+
+ printf("\n");
+ fflush(stdout);
+}
+
+static void stats_collect(struct stats_record *rec)
+{
+ int fd, i;
+
+ fd = map_fd[1]; /* map: rx_cnt */
+ map_collect_percpu(fd, 0, &rec->rx_cnt);
+
+ fd = map_fd[2]; /* map: redirect_err_cnt */
+ map_collect_percpu(fd, 1, &rec->redir_err);
+
+ fd = map_fd[3]; /* map: cpumap_enqueue_cnt */
+ for (i = 0; i < MAX_CPUS; i++)
+ map_collect_percpu(fd, i, &rec->enq[i]);
+
+ fd = map_fd[4]; /* map: cpumap_kthread_cnt */
+ map_collect_percpu(fd, 0, &rec->kthread);
+
+ fd = map_fd[8]; /* map: exception_cnt */
+ map_collect_percpu(fd, 0, &rec->exception);
+}
+
+
+/* Pointer swap trick */
+static inline void swap(struct stats_record **a, struct stats_record **b)
+{
+ struct stats_record *tmp;
+
+ tmp = *a;
+ *a = *b;
+ *b = tmp;
+}
+
+static int create_cpu_entry(__u32 cpu, __u32 queue_size,
+ __u32 avail_idx, bool new)
+{
+ __u32 curr_cpus_count = 0;
+ __u32 key = 0;
+ int ret;
+
+ /* Add a CPU entry to cpumap, as this allocate a cpu entry in
+ * the kernel for the cpu.
+ */
+ ret = bpf_map_update_elem(map_fd[0], &cpu, &queue_size, 0);
+ if (ret) {
+ fprintf(stderr, "Create CPU entry failed (err:%d)\n", ret);
+ exit(EXIT_FAIL_BPF);
+ }
+
+ /* Inform bpf_prog's that a new CPU is available to select
+ * from via some control maps.
+ */
+ /* map_fd[5] = cpus_available */
+ ret = bpf_map_update_elem(map_fd[5], &avail_idx, &cpu, 0);
+ if (ret) {
+ fprintf(stderr, "Add to avail CPUs failed\n");
+ exit(EXIT_FAIL_BPF);
+ }
+
+ /* When not replacing/updating existing entry, bump the count */
+ /* map_fd[6] = cpus_count */
+ ret = bpf_map_lookup_elem(map_fd[6], &key, &curr_cpus_count);
+ if (ret) {
+ fprintf(stderr, "Failed reading curr cpus_count\n");
+ exit(EXIT_FAIL_BPF);
+ }
+ if (new) {
+ curr_cpus_count++;
+ ret = bpf_map_update_elem(map_fd[6], &key, &curr_cpus_count, 0);
+ if (ret) {
+ fprintf(stderr, "Failed write curr cpus_count\n");
+ exit(EXIT_FAIL_BPF);
+ }
+ }
+ /* map_fd[7] = cpus_iterator */
+ printf("%s CPU:%u as idx:%u queue_size:%d (total cpus_count:%u)\n",
+ new ? "Add-new":"Replace", cpu, avail_idx,
+ queue_size, curr_cpus_count);
+
+ return 0;
+}
+
+/* CPUs are zero-indexed. Thus, add a special sentinel default value
+ * in map cpus_available to mark CPU index'es not configured
+ */
+static void mark_cpus_unavailable(void)
+{
+ __u32 invalid_cpu = MAX_CPUS;
+ int ret, i;
+
+ for (i = 0; i < MAX_CPUS; i++) {
+ /* map_fd[5] = cpus_available */
+ ret = bpf_map_update_elem(map_fd[5], &i, &invalid_cpu, 0);
+ if (ret) {
+ fprintf(stderr, "Failed marking CPU unavailable\n");
+ exit(EXIT_FAIL_BPF);
+ }
+ }
+}
+
+/* Stress cpumap management code by concurrently changing underlying cpumap */
+static void stress_cpumap(void)
+{
+ /* Changing qsize will cause kernel to free and alloc a new
+ * bpf_cpu_map_entry, with an associated/complicated tear-down
+ * procedure.
+ */
+ create_cpu_entry(1, 1024, 0, false);
+ create_cpu_entry(1, 128, 0, false);
+ create_cpu_entry(1, 16000, 0, false);
+}
+
+static void stats_poll(int interval, bool use_separators, int prog_num,
+ bool stress_mode)
+{
+ struct stats_record *record, *prev;
+
+ record = alloc_stats_record();
+ prev = alloc_stats_record();
+ stats_collect(record);
+
+ /* Trick to pretty printf with thousands separators use %' */
+ if (use_separators)
+ setlocale(LC_NUMERIC, "en_US");
+
+ while (1) {
+ swap(&prev, &record);
+ stats_collect(record);
+ stats_print(record, prev, prog_num);
+ sleep(interval);
+ if (stress_mode)
+ stress_cpumap();
+ }
+
+ free_stats_record(record);
+ free_stats_record(prev);
+}
+
+int main(int argc, char **argv)
+{
+ struct rlimit r = {10 * 1024 * 1024, RLIM_INFINITY};
+ bool use_separators = true;
+ bool stress_mode = false;
+ char filename[256];
+ bool debug = false;
+ int added_cpus = 0;
+ int longindex = 0;
+ int interval = 2;
+ int prog_num = 0;
+ int add_cpu = -1;
+ __u32 qsize;
+ int opt;
+
+ /* Notice: choosing he queue size is very important with the
+ * ixgbe driver, because it's driver page recycling trick is
+ * dependend on pages being returned quickly. The number of
+ * out-standing packets in the system must be less-than 2x
+ * RX-ring size.
+ */
+ qsize = 128+64;
+
+ snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
+
+ if (setrlimit(RLIMIT_MEMLOCK, &r)) {
+ perror("setrlimit(RLIMIT_MEMLOCK)");
+ return 1;
+ }
+
+ if (load_bpf_file(filename)) {
+ fprintf(stderr, "ERR in load_bpf_file(): %s", bpf_log_buf);
+ return EXIT_FAIL;
+ }
+
+ if (!prog_fd[0]) {
+ fprintf(stderr, "ERR: load_bpf_file: %s\n", strerror(errno));
+ return EXIT_FAIL;
+ }
+
+ mark_cpus_unavailable();
+
+ /* Parse commands line args */
+ while ((opt = getopt_long(argc, argv, "hSd:",
+ long_options, &longindex)) != -1) {
+ switch (opt) {
+ case 'd':
+ if (strlen(optarg) >= IF_NAMESIZE) {
+ fprintf(stderr, "ERR: --dev name too long\n");
+ goto error;
+ }
+ ifname = (char *)&ifname_buf;
+ strncpy(ifname, optarg, IF_NAMESIZE);
+ ifindex = if_nametoindex(ifname);
+ if (ifindex == 0) {
+ fprintf(stderr,
+ "ERR: --dev name unknown err(%d):%s\n",
+ errno, strerror(errno));
+ goto error;
+ }
+ break;
+ case 's':
+ interval = atoi(optarg);
+ break;
+ case 'S':
+ xdp_flags |= XDP_FLAGS_SKB_MODE;
+ break;
+ case 'D':
+ debug = true;
+ break;
+ case 'x':
+ stress_mode = true;
+ break;
+ case 'z':
+ use_separators = false;
+ break;
+ case 'p':
+ /* Selecting eBPF prog to load */
+ prog_num = atoi(optarg);
+ if (prog_num < 0 || prog_num >= MAX_PROG) {
+ fprintf(stderr,
+ "--prognum too large err(%d):%s\n",
+ errno, strerror(errno));
+ goto error;
+ }
+ break;
+ case 'c':
+ /* Add multiple CPUs */
+ add_cpu = strtoul(optarg, NULL, 0);
+ if (add_cpu >= MAX_CPUS) {
+ fprintf(stderr,
+ "--cpu nr too large for cpumap err(%d):%s\n",
+ errno, strerror(errno));
+ goto error;
+ }
+ create_cpu_entry(add_cpu, qsize, added_cpus, true);
+ added_cpus++;
+ break;
+ case 'q':
+ qsize = atoi(optarg);
+ break;
+ case 'h':
+ error:
+ default:
+ usage(argv);
+ return EXIT_FAIL_OPTION;
+ }
+ }
+ /* Required option */
+ if (ifindex == -1) {
+ fprintf(stderr, "ERR: required option --dev missing\n");
+ usage(argv);
+ return EXIT_FAIL_OPTION;
+ }
+ /* Required option */
+ if (add_cpu == -1) {
+ fprintf(stderr, "ERR: required option --cpu missing\n");
+ fprintf(stderr, " Specify multiple --cpu option to add more\n");
+ usage(argv);
+ return EXIT_FAIL_OPTION;
+ }
+
+ /* Remove XDP program when program is interrupted */
+ signal(SIGINT, int_exit);
+
+ if (set_link_xdp_fd(ifindex, prog_fd[prog_num], xdp_flags) < 0) {
+ fprintf(stderr, "link set xdp fd failed\n");
+ return EXIT_FAIL_XDP;
+ }
+
+ if (debug) {
+ printf("Debug-mode reading trace pipe (fix #define DEBUG)\n");
+ read_trace_pipe();
+ }
+
+ stats_poll(interval, use_separators, prog_num, stress_mode);
+ return EXIT_OK;
+}
^ permalink raw reply related
* [net-next V7 PATCH 4/5] bpf: cpumap add tracepoints
From: Jesper Dangaard Brouer @ 2017-10-12 12:27 UTC (permalink / raw)
To: netdev
Cc: jakub.kicinski, Michael S. Tsirkin, pavel.odintsov, Jason Wang,
mchan, John Fastabend, peter.waskiewicz.jr,
Jesper Dangaard Brouer, ast, Daniel Borkmann, Alexei Starovoitov,
Andy Gospodarek
In-Reply-To: <150781116384.9409.2491501775270038284.stgit@firesoul>
This adds two tracepoint to the cpumap. One for the enqueue side
trace_xdp_cpumap_enqueue() and one for the kthread dequeue side
trace_xdp_cpumap_kthread().
To mitigate the tracepoint overhead, these are invoked during the
enqueue/dequeue bulking phases, thus amortizing the cost.
The obvious use-cases are for debugging and monitoring. The
non-intuitive use-case is using these as a feedback loop to know the
system load. One can imagine auto-scaling by reducing, adding or
activating more worker CPUs on demand.
V4: tracepoint remove time_limit info, instead add sched info
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
include/trace/events/xdp.h | 70 ++++++++++++++++++++++++++++++++++++++++++++
kernel/bpf/cpumap.c | 23 +++++++++++---
2 files changed, 88 insertions(+), 5 deletions(-)
diff --git a/include/trace/events/xdp.h b/include/trace/events/xdp.h
index eb2ece96c1a2..0c8dec61987e 100644
--- a/include/trace/events/xdp.h
+++ b/include/trace/events/xdp.h
@@ -150,6 +150,76 @@ DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map_err,
trace_xdp_redirect_map_err(dev, xdp, devmap_ifindex(fwd, map), \
err, map, idx)
+TRACE_EVENT(xdp_cpumap_kthread,
+
+ TP_PROTO(int map_id, unsigned int processed, unsigned int drops,
+ int sched),
+
+ TP_ARGS(map_id, processed, drops, sched),
+
+ TP_STRUCT__entry(
+ __field(int, map_id)
+ __field(u32, act)
+ __field(int, cpu)
+ __field(unsigned int, drops)
+ __field(unsigned int, processed)
+ __field(int, sched)
+ ),
+
+ TP_fast_assign(
+ __entry->map_id = map_id;
+ __entry->act = XDP_REDIRECT;
+ __entry->cpu = smp_processor_id();
+ __entry->drops = drops;
+ __entry->processed = processed;
+ __entry->sched = sched;
+ ),
+
+ TP_printk("kthread"
+ " cpu=%d map_id=%d action=%s"
+ " processed=%u drops=%u"
+ " sched=%d",
+ __entry->cpu, __entry->map_id,
+ __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
+ __entry->processed, __entry->drops,
+ __entry->sched)
+);
+
+TRACE_EVENT(xdp_cpumap_enqueue,
+
+ TP_PROTO(int map_id, unsigned int processed, unsigned int drops,
+ int to_cpu),
+
+ TP_ARGS(map_id, processed, drops, to_cpu),
+
+ TP_STRUCT__entry(
+ __field(int, map_id)
+ __field(u32, act)
+ __field(int, cpu)
+ __field(unsigned int, drops)
+ __field(unsigned int, processed)
+ __field(int, to_cpu)
+ ),
+
+ TP_fast_assign(
+ __entry->map_id = map_id;
+ __entry->act = XDP_REDIRECT;
+ __entry->cpu = smp_processor_id();
+ __entry->drops = drops;
+ __entry->processed = processed;
+ __entry->to_cpu = to_cpu;
+ ),
+
+ TP_printk("enqueue"
+ " cpu=%d map_id=%d action=%s"
+ " processed=%u drops=%u"
+ " to_cpu=%d",
+ __entry->cpu, __entry->map_id,
+ __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
+ __entry->processed, __entry->drops,
+ __entry->to_cpu)
+);
+
#endif /* _TRACE_XDP_H */
#include <trace/define_trace.h>
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index cae73d95be00..7aec2c98ebb9 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -24,6 +24,7 @@
#include <linux/workqueue.h>
#include <linux/kthread.h>
#include <linux/capability.h>
+#include <trace/events/xdp.h>
#include <linux/netdevice.h> /* netif_receive_skb_core */
#include <linux/etherdevice.h> /* eth_type_trans */
@@ -282,15 +283,16 @@ static int cpu_map_kthread_run(void *data)
* kthread_stop signal until queue is empty.
*/
while (!kthread_should_stop() || !__ptr_ring_empty(rcpu->queue)) {
- unsigned int processed = 0, drops = 0;
+ unsigned int processed = 0, drops = 0, sched = 0;
struct xdp_pkt *xdp_pkt;
/* Release CPU reschedule checks */
if (__ptr_ring_empty(rcpu->queue)) {
__set_current_state(TASK_INTERRUPTIBLE);
schedule();
+ sched = 1;
} else {
- cond_resched();
+ sched = cond_resched();
}
__set_current_state(TASK_RUNNING);
@@ -320,6 +322,9 @@ static int cpu_map_kthread_run(void *data)
if (++processed == 8)
break;
}
+ /* Feedback loop via tracepoint */
+ trace_xdp_cpumap_kthread(rcpu->map_id, processed, drops, sched);
+
local_bh_enable(); /* resched point, may call do_softirq() */
}
__set_current_state(TASK_RUNNING);
@@ -355,7 +360,10 @@ struct bpf_cpu_map_entry *__cpu_map_entry_alloc(u32 qsize, u32 cpu, int map_id)
err = ptr_ring_init(rcpu->queue, qsize, gfp);
if (err)
goto free_queue;
- rcpu->qsize = qsize
+
+ rcpu->cpu = cpu;
+ rcpu->map_id = map_id;
+ rcpu->qsize = qsize;
/* Setup kthread */
rcpu->kthread = kthread_create_on_node(cpu_map_kthread_run, rcpu, numa,
@@ -585,6 +593,8 @@ const struct bpf_map_ops cpu_map_ops = {
static int bq_flush_to_queue(struct bpf_cpu_map_entry *rcpu,
struct xdp_bulk_queue *bq)
{
+ unsigned int processed = 0, drops = 0;
+ const int to_cpu = rcpu->cpu;
struct ptr_ring *q;
int i;
@@ -600,13 +610,16 @@ static int bq_flush_to_queue(struct bpf_cpu_map_entry *rcpu,
err = __ptr_ring_produce(q, xdp_pkt);
if (err) {
- /* Free xdp_pkt */
- page_frag_free(xdp_pkt);
+ drops++;
+ page_frag_free(xdp_pkt); /* Free xdp_pkt */
}
+ processed++;
}
bq->count = 0;
spin_unlock(&q->producer_lock);
+ /* Feedback loop via tracepoints */
+ trace_xdp_cpumap_enqueue(rcpu->map_id, processed, drops, to_cpu);
return 0;
}
^ permalink raw reply related
* [net-next V7 PATCH 3/5] bpf: cpumap xdp_buff to skb conversion and allocation
From: Jesper Dangaard Brouer @ 2017-10-12 12:26 UTC (permalink / raw)
To: netdev
Cc: jakub.kicinski, Michael S. Tsirkin, pavel.odintsov, Jason Wang,
mchan, John Fastabend, peter.waskiewicz.jr,
Jesper Dangaard Brouer, ast, Daniel Borkmann, Alexei Starovoitov,
Andy Gospodarek
In-Reply-To: <150781116384.9409.2491501775270038284.stgit@firesoul>
This patch makes cpumap functional, by adding SKB allocation and
invoking the network stack on the dequeuing CPU.
For constructing the SKB on the remote CPU, the xdp_buff in converted
into a struct xdp_pkt, and it mapped into the top headroom of the
packet, to avoid allocating separate mem. For now, struct xdp_pkt is
just a cpumap internal data structure, with info carried between
enqueue to dequeue.
If a driver doesn't have enough headroom it is simply dropped, with
return code -EOVERFLOW. This will be picked up the xdp tracepoint
infrastructure, to allow users to catch this.
V2: take into account xdp->data_meta
V4:
- Drop busypoll tricks, keeping it more simple.
- Skip RPS and Generic-XDP-recursive-reinjection, suggested by Alexei
V5: correct RCU read protection around __netif_receive_skb_core.
V6: Setting TASK_RUNNING vs TASK_INTERRUPTIBLE based on talk with Rik van Riel
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
include/linux/netdevice.h | 1
kernel/bpf/cpumap.c | 152 ++++++++++++++++++++++++++++++++++++++-------
net/core/dev.c | 27 ++++++++
3 files changed, 158 insertions(+), 22 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 31bb3010c69b..bf014afcb914 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3260,6 +3260,7 @@ int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb);
int netif_rx(struct sk_buff *skb);
int netif_rx_ni(struct sk_buff *skb);
int netif_receive_skb(struct sk_buff *skb);
+int netif_receive_skb_core(struct sk_buff *skb);
gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb);
void napi_gro_flush(struct napi_struct *napi, bool flush_old);
struct sk_buff *napi_get_frags(struct napi_struct *napi);
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index bc989a9ae049..cae73d95be00 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -25,6 +25,9 @@
#include <linux/kthread.h>
#include <linux/capability.h>
+#include <linux/netdevice.h> /* netif_receive_skb_core */
+#include <linux/etherdevice.h> /* eth_type_trans */
+
/* General idea: XDP packets getting XDP redirected to another CPU,
* will maximum be stored/queued for one driver ->poll() call. It is
* guaranteed that setting flush bit and flush operation happen on
@@ -181,6 +184,92 @@ static void cpu_map_kthread_stop(struct work_struct *work)
kthread_stop(rcpu->kthread);
}
+/* For now, xdp_pkt is a cpumap internal data structure, with info
+ * carried between enqueue to dequeue. It is mapped into the top
+ * headroom of the packet, to avoid allocating separate mem.
+ */
+struct xdp_pkt {
+ void *data;
+ u16 len;
+ u16 headroom;
+ u16 metasize;
+ struct net_device *dev_rx;
+};
+
+/* Convert xdp_buff to xdp_pkt */
+static struct xdp_pkt *convert_to_xdp_pkt(struct xdp_buff *xdp)
+{
+ struct xdp_pkt *xdp_pkt;
+ int metasize;
+ int headroom;
+
+ /* Assure headroom is available for storing info */
+ headroom = xdp->data - xdp->data_hard_start;
+ metasize = xdp->data - xdp->data_meta;
+ metasize = metasize > 0 ? metasize : 0;
+ if ((headroom - metasize) < sizeof(*xdp_pkt))
+ return NULL;
+
+ /* Store info in top of packet */
+ xdp_pkt = xdp->data_hard_start;
+
+ xdp_pkt->data = xdp->data;
+ xdp_pkt->len = xdp->data_end - xdp->data;
+ xdp_pkt->headroom = headroom - sizeof(*xdp_pkt);
+ xdp_pkt->metasize = metasize;
+
+ return xdp_pkt;
+}
+
+struct sk_buff *cpu_map_build_skb(struct bpf_cpu_map_entry *rcpu,
+ struct xdp_pkt *xdp_pkt)
+{
+ unsigned int frame_size;
+ void *pkt_data_start;
+ struct sk_buff *skb;
+
+ /* build_skb need to place skb_shared_info after SKB end, and
+ * also want to know the memory "truesize". Thus, need to
+ * know the memory frame size backing xdp_buff.
+ *
+ * XDP was designed to have PAGE_SIZE frames, but this
+ * assumption is not longer true with ixgbe and i40e. It
+ * would be preferred to set frame_size to 2048 or 4096
+ * depending on the driver.
+ * frame_size = 2048;
+ * frame_len = frame_size - sizeof(*xdp_pkt);
+ *
+ * Instead, with info avail, skb_shared_info in placed after
+ * packet len. This, unfortunately fakes the truesize.
+ * Another disadvantage of this approach, the skb_shared_info
+ * is not at a fixed memory location, with mixed length
+ * packets, which is bad for cache-line hotness.
+ */
+ frame_size = SKB_DATA_ALIGN(xdp_pkt->len) + xdp_pkt->headroom +
+ SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+
+ pkt_data_start = xdp_pkt->data - xdp_pkt->headroom;
+ skb = build_skb(pkt_data_start, frame_size);
+ if (!skb)
+ return NULL;
+
+ skb_reserve(skb, xdp_pkt->headroom);
+ __skb_put(skb, xdp_pkt->len);
+ if (xdp_pkt->metasize)
+ skb_metadata_set(skb, xdp_pkt->metasize);
+
+ /* Essential SKB info: protocol and skb->dev */
+ skb->protocol = eth_type_trans(skb, xdp_pkt->dev_rx);
+
+ /* Optional SKB info, currently missing:
+ * - HW checksum info (skb->ip_summed)
+ * - HW RX hash (skb_set_hash)
+ * - RX ring dev queue index (skb_record_rx_queue)
+ */
+
+ return skb;
+}
+
static int cpu_map_kthread_run(void *data)
{
struct bpf_cpu_map_entry *rcpu = data;
@@ -193,15 +282,45 @@ static int cpu_map_kthread_run(void *data)
* kthread_stop signal until queue is empty.
*/
while (!kthread_should_stop() || !__ptr_ring_empty(rcpu->queue)) {
+ unsigned int processed = 0, drops = 0;
struct xdp_pkt *xdp_pkt;
- schedule();
- /* Do work */
- while ((xdp_pkt = ptr_ring_consume(rcpu->queue))) {
- /* For now just "refcnt-free" */
- page_frag_free(xdp_pkt);
+ /* Release CPU reschedule checks */
+ if (__ptr_ring_empty(rcpu->queue)) {
+ __set_current_state(TASK_INTERRUPTIBLE);
+ schedule();
+ } else {
+ cond_resched();
+ }
+ __set_current_state(TASK_RUNNING);
+
+ /* Process packets in rcpu->queue */
+ local_bh_disable();
+ /*
+ * The bpf_cpu_map_entry is single consumer, with this
+ * kthread CPU pinned. Lockless access to ptr_ring
+ * consume side valid as no-resize allowed of queue.
+ */
+ while ((xdp_pkt = __ptr_ring_consume(rcpu->queue))) {
+ struct sk_buff *skb;
+ int ret;
+
+ skb = cpu_map_build_skb(rcpu, xdp_pkt);
+ if (!skb) {
+ page_frag_free(xdp_pkt);
+ continue;
+ }
+
+ /* Inject into network stack */
+ ret = netif_receive_skb_core(skb);
+ if (ret == NET_RX_DROP)
+ drops++;
+
+ /* Limit BH-disable period */
+ if (++processed == 8)
+ break;
}
- __set_current_state(TASK_INTERRUPTIBLE);
+ local_bh_enable(); /* resched point, may call do_softirq() */
}
__set_current_state(TASK_RUNNING);
@@ -491,13 +610,6 @@ static int bq_flush_to_queue(struct bpf_cpu_map_entry *rcpu,
return 0;
}
-/* Notice: Will change in later patch */
-struct xdp_pkt {
- void *data;
- u16 len;
- u16 headroom;
-};
-
/* Runs under RCU-read-side, plus in softirq under NAPI protection.
* Thus, safe percpu variable access.
*/
@@ -525,17 +637,13 @@ int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
struct net_device *dev_rx)
{
struct xdp_pkt *xdp_pkt;
- int headroom;
- /* For now this is just used as a void pointer to data_hard_start.
- * Followup patch will generalize this.
- */
- xdp_pkt = xdp->data_hard_start;
+ xdp_pkt = convert_to_xdp_pkt(xdp);
+ if (!xdp_pkt)
+ return -EOVERFLOW;
- /* Fake writing into xdp_pkt->data to measure overhead */
- headroom = xdp->data - xdp->data_hard_start;
- if (headroom < sizeof(*xdp_pkt))
- xdp_pkt->data = xdp->data;
+ /* Info needed when constructing SKB on remote CPU */
+ xdp_pkt->dev_rx = dev_rx;
bq_enqueue(rcpu, xdp_pkt);
return 0;
diff --git a/net/core/dev.c b/net/core/dev.c
index fcddccb6be41..36bb68f3a2c7 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4491,6 +4491,33 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc)
return ret;
}
+/**
+ * netif_receive_skb_core - special purpose version of netif_receive_skb
+ * @skb: buffer to process
+ *
+ * More direct receive version of netif_receive_skb(). It should
+ * only be used by callers that have a need to skip RPS and Generic XDP.
+ * Caller must also take care of handling if (page_is_)pfmemalloc.
+ *
+ * This function may only be called from softirq context and interrupts
+ * should be enabled.
+ *
+ * Return values (usually ignored):
+ * NET_RX_SUCCESS: no congestion
+ * NET_RX_DROP: packet was dropped
+ */
+int netif_receive_skb_core(struct sk_buff *skb)
+{
+ int ret;
+
+ rcu_read_lock();
+ ret = __netif_receive_skb_core(skb, false);
+ rcu_read_unlock();
+
+ return ret;
+}
+EXPORT_SYMBOL(netif_receive_skb_core);
+
static int __netif_receive_skb(struct sk_buff *skb)
{
int ret;
^ permalink raw reply related
* [net-next V7 PATCH 1/5] bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP
From: Jesper Dangaard Brouer @ 2017-10-12 12:26 UTC (permalink / raw)
To: netdev
Cc: jakub.kicinski, Michael S. Tsirkin, pavel.odintsov, Jason Wang,
mchan, John Fastabend, peter.waskiewicz.jr,
Jesper Dangaard Brouer, ast, Daniel Borkmann, Alexei Starovoitov,
Andy Gospodarek
In-Reply-To: <150781116384.9409.2491501775270038284.stgit@firesoul>
The 'cpumap' is primary used as a backend map for XDP BPF helper
call bpf_redirect_map() and XDP_REDIRECT action, like 'devmap'.
This patch implement the main part of the map. It is not connected to
the XDP redirect system yet, and no SKB allocation are done yet.
The main concern in this patch is to ensure the datapath can run
without any locking. This adds complexity to the setup and tear-down
procedure, which assumptions are extra carefully documented in the
code comments.
V2:
- make sure array isn't larger than NR_CPUS
- make sure CPUs added is a valid possible CPU
V3: fix nitpicks from Jakub Kicinski <kubakici@wp.pl>
V5:
- Restrict map allocation to root / CAP_SYS_ADMIN
- WARN_ON_ONCE if queue is not empty on tear-down
- Return -EPERM on memlock limit instead of -ENOMEM
- Error code in __cpu_map_entry_alloc() also handle ptr_ring_cleanup()
- Moved cpu_map_enqueue() to next patch
V6: all notice by Daniel Borkmann
- Fix err return code in cpu_map_alloc() introduced in V5
- Move cpu_possible() check after max_entries boundary check
- Forbid usage initially in check_map_func_compatibility()
V7:
- Fix alloc error path spotted by Daniel Borkmann
- Did stress test adding+removing CPUs from the map concurrently
- Fixed refcnt issue on cpu_map_entry, kthread started too soon
- Make sure packets are flushed during tear-down, involved use of
rcu_barrier() and kthread_run only exit after queue is empty
- Fix alloc error path in __cpu_map_entry_alloc() for ptr_ring
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
include/linux/bpf_types.h | 1
include/uapi/linux/bpf.h | 1
kernel/bpf/Makefile | 1
kernel/bpf/cpumap.c | 561 ++++++++++++++++++++++++++++++++++++++++
kernel/bpf/syscall.c | 8 -
kernel/bpf/verifier.c | 5
tools/include/uapi/linux/bpf.h | 1
7 files changed, 577 insertions(+), 1 deletion(-)
create mode 100644 kernel/bpf/cpumap.c
diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h
index 6f1a567667b8..814c1081a4a9 100644
--- a/include/linux/bpf_types.h
+++ b/include/linux/bpf_types.h
@@ -41,4 +41,5 @@ BPF_MAP_TYPE(BPF_MAP_TYPE_DEVMAP, dev_map_ops)
#ifdef CONFIG_STREAM_PARSER
BPF_MAP_TYPE(BPF_MAP_TYPE_SOCKMAP, sock_map_ops)
#endif
+BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
#endif
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 6db9e1d679cd..4303fb6c3817 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -112,6 +112,7 @@ enum bpf_map_type {
BPF_MAP_TYPE_HASH_OF_MAPS,
BPF_MAP_TYPE_DEVMAP,
BPF_MAP_TYPE_SOCKMAP,
+ BPF_MAP_TYPE_CPUMAP,
};
enum bpf_prog_type {
diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index 897daa005b23..dba0bd33a43c 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o
obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o
ifeq ($(CONFIG_NET),y)
obj-$(CONFIG_BPF_SYSCALL) += devmap.o
+obj-$(CONFIG_BPF_SYSCALL) += cpumap.o
ifeq ($(CONFIG_STREAM_PARSER),y)
obj-$(CONFIG_BPF_SYSCALL) += sockmap.o
endif
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
new file mode 100644
index 000000000000..34db22afcca2
--- /dev/null
+++ b/kernel/bpf/cpumap.c
@@ -0,0 +1,561 @@
+/* bpf/cpumap.c
+ *
+ * Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc.
+ * Released under terms in GPL version 2. See COPYING.
+ */
+
+/* The 'cpumap' is primary used as a backend map for XDP BPF helper
+ * call bpf_redirect_map() and XDP_REDIRECT action, like 'devmap'.
+ *
+ * Unlike devmap which redirect XDP frames out another NIC device,
+ * this map type redirect raw XDP frames to another CPU. The remote
+ * CPU will do SKB-allocation and call the normal network stack.
+ *
+ * This is a scalability and isolation mechanism, that allow
+ * separating the early driver network XDP layer, from the rest of the
+ * netstack, and assigning dedicated CPUs for this stage. This
+ * basically allows for 10G wirespeed pre-filtering via bpf.
+ */
+#include <linux/bpf.h>
+#include <linux/filter.h>
+#include <linux/ptr_ring.h>
+
+#include <linux/sched.h>
+#include <linux/workqueue.h>
+#include <linux/kthread.h>
+#include <linux/capability.h>
+
+/* General idea: XDP packets getting XDP redirected to another CPU,
+ * will maximum be stored/queued for one driver ->poll() call. It is
+ * guaranteed that setting flush bit and flush operation happen on
+ * same CPU. Thus, cpu_map_flush operation can deduct via this_cpu_ptr()
+ * which queue in bpf_cpu_map_entry contains packets.
+ */
+
+#define CPU_MAP_BULK_SIZE 8 /* 8 == one cacheline on 64-bit archs */
+struct xdp_bulk_queue {
+ void *q[CPU_MAP_BULK_SIZE];
+ unsigned int count;
+};
+
+/* Struct for every remote "destination" CPU in map */
+struct bpf_cpu_map_entry {
+ u32 cpu; /* kthread CPU and map index */
+ int map_id; /* Back reference to map */
+ u32 qsize; /* Redundant queue size for map lookup */
+
+ /* XDP can run multiple RX-ring queues, need __percpu enqueue store */
+ struct xdp_bulk_queue __percpu *bulkq;
+
+ /* Queue with potential multi-producers, and single-consumer kthread */
+ struct ptr_ring *queue;
+ struct task_struct *kthread;
+ struct work_struct kthread_stop_wq;
+
+ atomic_t refcnt; /* Control when this struct can be free'ed */
+ struct rcu_head rcu;
+};
+
+struct bpf_cpu_map {
+ struct bpf_map map;
+ /* Below members specific for map type */
+ struct bpf_cpu_map_entry **cpu_map;
+ unsigned long __percpu *flush_needed;
+};
+
+static int bq_flush_to_queue(struct bpf_cpu_map_entry *rcpu,
+ struct xdp_bulk_queue *bq);
+
+static u64 cpu_map_bitmap_size(const union bpf_attr *attr)
+{
+ return BITS_TO_LONGS(attr->max_entries) * sizeof(unsigned long);
+}
+
+static struct bpf_map *cpu_map_alloc(union bpf_attr *attr)
+{
+ struct bpf_cpu_map *cmap;
+ int err = -ENOMEM;
+ u64 cost;
+ int ret;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return ERR_PTR(-EPERM);
+
+ /* check sanity of attributes */
+ if (attr->max_entries == 0 || attr->key_size != 4 ||
+ attr->value_size != 4 || attr->map_flags & ~BPF_F_NUMA_NODE)
+ return ERR_PTR(-EINVAL);
+
+ cmap = kzalloc(sizeof(*cmap), GFP_USER);
+ if (!cmap)
+ return ERR_PTR(-ENOMEM);
+
+ /* mandatory map attributes */
+ cmap->map.map_type = attr->map_type;
+ cmap->map.key_size = attr->key_size;
+ cmap->map.value_size = attr->value_size;
+ cmap->map.max_entries = attr->max_entries;
+ cmap->map.map_flags = attr->map_flags;
+ cmap->map.numa_node = bpf_map_attr_numa_node(attr);
+
+ /* Pre-limit array size based on NR_CPUS, not final CPU check */
+ if (cmap->map.max_entries > NR_CPUS) {
+ err = -E2BIG;
+ goto free_cmap;
+ }
+
+ /* make sure page count doesn't overflow */
+ cost = (u64) cmap->map.max_entries * sizeof(struct bpf_cpu_map_entry *);
+ cost += cpu_map_bitmap_size(attr) * num_possible_cpus();
+ if (cost >= U32_MAX - PAGE_SIZE)
+ goto free_cmap;
+ cmap->map.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;
+
+ /* Notice returns -EPERM on if map size is larger than memlock limit */
+ ret = bpf_map_precharge_memlock(cmap->map.pages);
+ if (ret) {
+ err = ret;
+ goto free_cmap;
+ }
+
+ /* A per cpu bitfield with a bit per possible CPU in map */
+ cmap->flush_needed = __alloc_percpu(cpu_map_bitmap_size(attr),
+ __alignof__(unsigned long));
+ if (!cmap->flush_needed)
+ goto free_cmap;
+
+ /* Alloc array for possible remote "destination" CPUs */
+ cmap->cpu_map = bpf_map_area_alloc(cmap->map.max_entries *
+ sizeof(struct bpf_cpu_map_entry *),
+ cmap->map.numa_node);
+ if (!cmap->cpu_map)
+ goto free_percpu;
+
+ return &cmap->map;
+free_percpu:
+ free_percpu(cmap->flush_needed);
+free_cmap:
+ kfree(cmap);
+ return ERR_PTR(err);
+}
+
+void __cpu_map_queue_destructor(void *ptr)
+{
+ /* The tear-down procedure should have made sure that queue is
+ * empty. See __cpu_map_entry_replace() and work-queue
+ * invoked cpu_map_kthread_stop(). Catch any broken behaviour
+ * gracefully and warn once.
+ */
+ if (WARN_ON_ONCE(ptr))
+ page_frag_free(ptr);
+}
+
+static void put_cpu_map_entry(struct bpf_cpu_map_entry *rcpu)
+{
+ if (atomic_dec_and_test(&rcpu->refcnt)) {
+ /* The queue should be empty at this point */
+ ptr_ring_cleanup(rcpu->queue, __cpu_map_queue_destructor);
+ kfree(rcpu->queue);
+ kfree(rcpu);
+ }
+}
+
+static void get_cpu_map_entry(struct bpf_cpu_map_entry *rcpu)
+{
+ atomic_inc(&rcpu->refcnt);
+}
+
+/* called from workqueue, to workaround syscall using preempt_disable */
+static void cpu_map_kthread_stop(struct work_struct *work)
+{
+ struct bpf_cpu_map_entry *rcpu;
+
+ rcpu = container_of(work, struct bpf_cpu_map_entry, kthread_stop_wq);
+
+ /* Wait for flush in __cpu_map_entry_free(), via full RCU barrier,
+ * as it waits until all in-flight call_rcu() callbacks complete.
+ */
+ rcu_barrier();
+
+ /* kthread_stop will wake_up_process and wait for it to complete */
+ kthread_stop(rcpu->kthread);
+}
+
+static int cpu_map_kthread_run(void *data)
+{
+ struct bpf_cpu_map_entry *rcpu = data;
+
+ set_current_state(TASK_INTERRUPTIBLE);
+
+ /* When kthread gives stop order, then rcpu have been disconnected
+ * from map, thus no new packets can enter. Remaining in-flight
+ * per CPU stored packets are flushed to this queue. Wait honoring
+ * kthread_stop signal until queue is empty.
+ */
+ while (!kthread_should_stop() || !__ptr_ring_empty(rcpu->queue)) {
+ struct xdp_pkt *xdp_pkt;
+
+ schedule();
+ /* Do work */
+ while ((xdp_pkt = ptr_ring_consume(rcpu->queue))) {
+ /* For now just "refcnt-free" */
+ page_frag_free(xdp_pkt);
+ }
+ __set_current_state(TASK_INTERRUPTIBLE);
+ }
+ __set_current_state(TASK_RUNNING);
+
+ put_cpu_map_entry(rcpu);
+ return 0;
+}
+
+struct bpf_cpu_map_entry *__cpu_map_entry_alloc(u32 qsize, u32 cpu, int map_id)
+{
+ gfp_t gfp = GFP_ATOMIC|__GFP_NOWARN;
+ struct bpf_cpu_map_entry *rcpu;
+ int numa, err;
+
+ /* Have map->numa_node, but choose node of redirect target CPU */
+ numa = cpu_to_node(cpu);
+
+ rcpu = kzalloc_node(sizeof(*rcpu), gfp, numa);
+ if (!rcpu)
+ return NULL;
+
+ /* Alloc percpu bulkq */
+ rcpu->bulkq = __alloc_percpu_gfp(sizeof(*rcpu->bulkq),
+ sizeof(void *), gfp);
+ if (!rcpu->bulkq)
+ goto free_rcu;
+
+ /* Alloc queue */
+ rcpu->queue = kzalloc_node(sizeof(*rcpu->queue), gfp, numa);
+ if (!rcpu->queue)
+ goto free_bulkq;
+
+ err = ptr_ring_init(rcpu->queue, qsize, gfp);
+ if (err)
+ goto free_queue;
+ rcpu->qsize = qsize
+
+ /* Setup kthread */
+ rcpu->kthread = kthread_create_on_node(cpu_map_kthread_run, rcpu, numa,
+ "cpumap/%d/map:%d", cpu, map_id);
+ if (IS_ERR(rcpu->kthread))
+ goto free_ptr_ring;
+
+ get_cpu_map_entry(rcpu); /* 1-refcnt for being in cmap->cpu_map[] */
+ get_cpu_map_entry(rcpu); /* 1-refcnt for kthread */
+
+ /* Make sure kthread runs on a single CPU */
+ kthread_bind(rcpu->kthread, cpu);
+ wake_up_process(rcpu->kthread);
+
+ return rcpu;
+
+free_ptr_ring:
+ ptr_ring_cleanup(rcpu->queue, NULL);
+free_queue:
+ kfree(rcpu->queue);
+free_bulkq:
+ free_percpu(rcpu->bulkq);
+free_rcu:
+ kfree(rcpu);
+ return NULL;
+}
+
+void __cpu_map_entry_free(struct rcu_head *rcu)
+{
+ struct bpf_cpu_map_entry *rcpu;
+ int cpu;
+
+ /* This cpu_map_entry have been disconnected from map and one
+ * RCU graze-period have elapsed. Thus, XDP cannot queue any
+ * new packets and cannot change/set flush_needed that can
+ * find this entry.
+ */
+ rcpu = container_of(rcu, struct bpf_cpu_map_entry, rcu);
+
+ /* Flush remaining packets in percpu bulkq */
+ for_each_online_cpu(cpu) {
+ struct xdp_bulk_queue *bq = per_cpu_ptr(rcpu->bulkq, cpu);
+
+ /* No concurrent bq_enqueue can run at this point */
+ bq_flush_to_queue(rcpu, bq);
+ }
+ free_percpu(rcpu->bulkq);
+ /* Cannot kthread_stop() here, last put free rcpu resources */
+ put_cpu_map_entry(rcpu);
+}
+
+/* After xchg pointer to bpf_cpu_map_entry, use the call_rcu() to
+ * ensure any driver rcu critical sections have completed, but this
+ * does not guarantee a flush has happened yet. Because driver side
+ * rcu_read_lock/unlock only protects the running XDP program. The
+ * atomic xchg and NULL-ptr check in __cpu_map_flush() makes sure a
+ * pending flush op doesn't fail.
+ *
+ * The bpf_cpu_map_entry is still used by the kthread, and there can
+ * still be pending packets (in queue and percpu bulkq). A refcnt
+ * makes sure to last user (kthread_stop vs. call_rcu) free memory
+ * resources.
+ *
+ * The rcu callback __cpu_map_entry_free flush remaining packets in
+ * percpu bulkq to queue. Due to caller map_delete_elem() disable
+ * preemption, cannot call kthread_stop() to make sure queue is empty.
+ * Instead a work_queue is started for stopping kthread,
+ * cpu_map_kthread_stop, which waits for an RCU graze period before
+ * stopping kthread, emptying the queue.
+ */
+void __cpu_map_entry_replace(struct bpf_cpu_map *cmap,
+ u32 key_cpu, struct bpf_cpu_map_entry *rcpu)
+{
+ struct bpf_cpu_map_entry *old_rcpu;
+
+ old_rcpu = xchg(&cmap->cpu_map[key_cpu], rcpu);
+ if (old_rcpu) {
+ call_rcu(&old_rcpu->rcu, __cpu_map_entry_free);
+ INIT_WORK(&old_rcpu->kthread_stop_wq, cpu_map_kthread_stop);
+ schedule_work(&old_rcpu->kthread_stop_wq);
+ }
+}
+
+int cpu_map_delete_elem(struct bpf_map *map, void *key)
+{
+ struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
+ u32 key_cpu = *(u32 *)key;
+
+ if (key_cpu >= map->max_entries)
+ return -EINVAL;
+
+ /* notice caller map_delete_elem() use preempt_disable() */
+ __cpu_map_entry_replace(cmap, key_cpu, NULL);
+ return 0;
+}
+
+int cpu_map_update_elem(struct bpf_map *map, void *key, void *value,
+ u64 map_flags)
+{
+ struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
+ struct bpf_cpu_map_entry *rcpu;
+
+ /* Array index key correspond to CPU number */
+ u32 key_cpu = *(u32 *)key;
+ /* Value is the queue size */
+ u32 qsize = *(u32 *)value;
+
+ if (unlikely(map_flags > BPF_EXIST))
+ return -EINVAL;
+ if (unlikely(key_cpu >= cmap->map.max_entries))
+ return -E2BIG;
+ if (unlikely(map_flags == BPF_NOEXIST))
+ return -EEXIST;
+ if (unlikely(qsize > 16384)) /* sanity limit on qsize */
+ return -EOVERFLOW;
+
+ /* Make sure CPU is a valid possible cpu */
+ if (!cpu_possible(key_cpu))
+ return -ENODEV;
+
+ if (qsize == 0) {
+ rcpu = NULL; /* Same as deleting */
+ } else {
+ /* Updating qsize cause re-allocation of bpf_cpu_map_entry */
+ rcpu = __cpu_map_entry_alloc(qsize, key_cpu, map->id);
+ if (!rcpu)
+ return -ENOMEM;
+ }
+ rcu_read_lock();
+ __cpu_map_entry_replace(cmap, key_cpu, rcpu);
+ rcu_read_unlock();
+ return 0;
+}
+
+void cpu_map_free(struct bpf_map *map)
+{
+ struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
+ int cpu;
+ u32 i;
+
+ /* At this point bpf_prog->aux->refcnt == 0 and this map->refcnt == 0,
+ * so the bpf programs (can be more than one that used this map) were
+ * disconnected from events. Wait for outstanding critical sections in
+ * these programs to complete. The rcu critical section only guarantees
+ * no further "XDP/bpf-side" reads against bpf_cpu_map->cpu_map.
+ * It does __not__ ensure pending flush operations (if any) are
+ * complete.
+ */
+ synchronize_rcu();
+
+ /* To ensure all pending flush operations have completed wait for flush
+ * bitmap to indicate all flush_needed bits to be zero on _all_ cpus.
+ * Because the above synchronize_rcu() ensures the map is disconnected
+ * from the program we can assume no new bits will be set.
+ */
+ for_each_online_cpu(cpu) {
+ unsigned long *bitmap = per_cpu_ptr(cmap->flush_needed, cpu);
+
+ while (!bitmap_empty(bitmap, cmap->map.max_entries))
+ cond_resched();
+ }
+
+ /* For cpu_map the remote CPUs can still be using the entries
+ * (struct bpf_cpu_map_entry).
+ */
+ for (i = 0; i < cmap->map.max_entries; i++) {
+ struct bpf_cpu_map_entry *rcpu;
+
+ rcpu = READ_ONCE(cmap->cpu_map[i]);
+ if (!rcpu)
+ continue;
+
+ /* bq flush and cleanup happens after RCU graze-period */
+ __cpu_map_entry_replace(cmap, i, NULL); /* call_rcu */
+ }
+ free_percpu(cmap->flush_needed);
+ bpf_map_area_free(cmap->cpu_map);
+ kfree(cmap);
+}
+
+struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key)
+{
+ struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
+ struct bpf_cpu_map_entry *rcpu;
+
+ if (key >= map->max_entries)
+ return NULL;
+
+ rcpu = READ_ONCE(cmap->cpu_map[key]);
+ return rcpu;
+}
+
+static void *cpu_map_lookup_elem(struct bpf_map *map, void *key)
+{
+ struct bpf_cpu_map_entry *rcpu =
+ __cpu_map_lookup_elem(map, *(u32 *)key);
+
+ return rcpu ? &rcpu->qsize : NULL;
+}
+
+static int cpu_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
+{
+ struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
+ u32 index = key ? *(u32 *)key : U32_MAX;
+ u32 *next = next_key;
+
+ if (index >= cmap->map.max_entries) {
+ *next = 0;
+ return 0;
+ }
+
+ if (index == cmap->map.max_entries - 1)
+ return -ENOENT;
+ *next = index + 1;
+ return 0;
+}
+
+const struct bpf_map_ops cpu_map_ops = {
+ .map_alloc = cpu_map_alloc,
+ .map_free = cpu_map_free,
+ .map_delete_elem = cpu_map_delete_elem,
+ .map_update_elem = cpu_map_update_elem,
+ .map_lookup_elem = cpu_map_lookup_elem,
+ .map_get_next_key = cpu_map_get_next_key,
+};
+
+static int bq_flush_to_queue(struct bpf_cpu_map_entry *rcpu,
+ struct xdp_bulk_queue *bq)
+{
+ struct ptr_ring *q;
+ int i;
+
+ if (unlikely(!bq->count))
+ return 0;
+
+ q = rcpu->queue;
+ spin_lock(&q->producer_lock);
+
+ for (i = 0; i < bq->count; i++) {
+ void *xdp_pkt = bq->q[i];
+ int err;
+
+ err = __ptr_ring_produce(q, xdp_pkt);
+ if (err) {
+ /* Free xdp_pkt */
+ page_frag_free(xdp_pkt);
+ }
+ }
+ bq->count = 0;
+ spin_unlock(&q->producer_lock);
+
+ return 0;
+}
+
+/* Notice: Will change in later patch */
+struct xdp_pkt {
+ void *data;
+ u16 len;
+ u16 headroom;
+};
+
+/* Runs under RCU-read-side, plus in softirq under NAPI protection.
+ * Thus, safe percpu variable access.
+ */
+int bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_pkt *xdp_pkt)
+{
+ struct xdp_bulk_queue *bq = this_cpu_ptr(rcpu->bulkq);
+
+ if (unlikely(bq->count == CPU_MAP_BULK_SIZE))
+ bq_flush_to_queue(rcpu, bq);
+
+ /* Notice, xdp_buff/page MUST be queued here, long enough for
+ * driver to code invoking us to finished, due to driver
+ * (e.g. ixgbe) recycle tricks based on page-refcnt.
+ *
+ * Thus, incoming xdp_pkt is always queued here (else we race
+ * with another CPU on page-refcnt and remaining driver code).
+ * Queue time is very short, as driver will invoke flush
+ * operation, when completing napi->poll call.
+ */
+ bq->q[bq->count++] = xdp_pkt;
+ return 0;
+}
+
+void __cpu_map_insert_ctx(struct bpf_map *map, u32 bit)
+{
+ struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
+ unsigned long *bitmap = this_cpu_ptr(cmap->flush_needed);
+
+ __set_bit(bit, bitmap);
+}
+
+void __cpu_map_flush(struct bpf_map *map)
+{
+ struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
+ unsigned long *bitmap = this_cpu_ptr(cmap->flush_needed);
+ u32 bit;
+
+ /* The napi->poll softirq makes sure __cpu_map_insert_ctx()
+ * and __cpu_map_flush() happen on same CPU. Thus, the percpu
+ * bitmap indicate which percpu bulkq have packets.
+ */
+ for_each_set_bit(bit, bitmap, map->max_entries) {
+ struct bpf_cpu_map_entry *rcpu = READ_ONCE(cmap->cpu_map[bit]);
+ struct xdp_bulk_queue *bq;
+
+ /* This is possible if entry is removed by user space
+ * between xdp redirect and flush op.
+ */
+ if (unlikely(!rcpu))
+ continue;
+
+ __clear_bit(bit, bitmap);
+
+ /* Flush all frames in bulkq to real queue */
+ bq = this_cpu_ptr(rcpu->bulkq);
+ bq_flush_to_queue(rcpu, bq);
+
+ /* If already running, costs spin_lock_irqsave + smb_mb */
+ wake_up_process(rcpu->kthread);
+ }
+}
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index d124e702e040..54fba06942f5 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -592,6 +592,12 @@ static int map_update_elem(union bpf_attr *attr)
if (copy_from_user(value, uvalue, value_size) != 0)
goto free_value;
+ /* Need to create a kthread, thus must support schedule */
+ if (map->map_type == BPF_MAP_TYPE_CPUMAP) {
+ err = map->ops->map_update_elem(map, key, value, attr->flags);
+ goto out;
+ }
+
/* must increment bpf_prog_active to avoid kprobe+bpf triggering from
* inside bpf map update or delete otherwise deadlocks are possible
*/
@@ -622,7 +628,7 @@ static int map_update_elem(union bpf_attr *attr)
}
__this_cpu_dec(bpf_prog_active);
preempt_enable();
-
+out:
if (!err)
trace_bpf_map_update_elem(map, ufd, key, value);
free_value:
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 6352a88ca6d1..d63fb96f114e 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1577,6 +1577,11 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id)
if (func_id != BPF_FUNC_redirect_map)
goto error;
break;
+ /* Restrict bpf side of cpumap, open when use-cases appear */
+ case BPF_MAP_TYPE_CPUMAP:
+ if (func_id != BPF_FUNC_redirect_map)
+ goto error;
+ break;
case BPF_MAP_TYPE_ARRAY_OF_MAPS:
case BPF_MAP_TYPE_HASH_OF_MAPS:
if (func_id != BPF_FUNC_map_lookup_elem)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index fb4fb81ce5b0..fa93033dc521 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -112,6 +112,7 @@ enum bpf_map_type {
BPF_MAP_TYPE_HASH_OF_MAPS,
BPF_MAP_TYPE_DEVMAP,
BPF_MAP_TYPE_SOCKMAP,
+ BPF_MAP_TYPE_CPUMAP,
};
enum bpf_prog_type {
^ permalink raw reply related
* [net-next V7 PATCH 2/5] bpf: XDP_REDIRECT enable use of cpumap
From: Jesper Dangaard Brouer @ 2017-10-12 12:26 UTC (permalink / raw)
To: netdev
Cc: jakub.kicinski, Michael S. Tsirkin, pavel.odintsov, Jason Wang,
mchan, John Fastabend, peter.waskiewicz.jr,
Jesper Dangaard Brouer, ast, Daniel Borkmann, Alexei Starovoitov,
Andy Gospodarek
In-Reply-To: <150781116384.9409.2491501775270038284.stgit@firesoul>
This patch connects cpumap to the xdp_do_redirect_map infrastructure.
Still no SKB allocation are done yet. The XDP frames are transferred
to the other CPU, but they are simply refcnt decremented on the remote
CPU. This served as a good benchmark for measuring the overhead of
remote refcnt decrement. If driver page recycle cache is not
efficient then this, exposes a bottleneck in the page allocator.
A shout-out to MST's ptr_ring, which is the secret behind is being so
efficient to transfer memory pointers between CPUs, without constantly
bouncing cache-lines between CPUs.
V3: Handle !CONFIG_BPF_SYSCALL pointed out by kbuild test robot.
V4: Make Generic-XDP aware of cpumap type, but don't allow redirect yet,
as implementation require a separate upstream discussion.
V5:
- Fix a maybe-uninitialized pointed out by kbuild test robot.
- Restrict bpf-prog side access to cpumap, open when use-cases appear
- Implement cpu_map_enqueue() as a more simple void pointer enqueue
V6:
- Allow cpumap type for usage in helper bpf_redirect_map,
general bpf-prog side restriction moved to earlier patch.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
include/linux/bpf.h | 31 +++++++++-
include/trace/events/xdp.h | 10 +++
kernel/bpf/cpumap.c | 22 +++++++
kernel/bpf/verifier.c | 3 +
net/core/filter.c | 140 +++++++++++++++++++++++++++++++++++---------
5 files changed, 172 insertions(+), 34 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 4373125de1f3..6d4dd844828a 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -355,6 +355,13 @@ struct net_device *__dev_map_lookup_elem(struct bpf_map *map, u32 key);
void __dev_map_insert_ctx(struct bpf_map *map, u32 index);
void __dev_map_flush(struct bpf_map *map);
+struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key);
+void __cpu_map_insert_ctx(struct bpf_map *map, u32 index);
+void __cpu_map_flush(struct bpf_map *map);
+struct xdp_buff;
+int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
+ struct net_device *dev_rx);
+
/* Return map's numa specified by userspace */
static inline int bpf_map_attr_numa_node(const union bpf_attr *attr)
{
@@ -362,7 +369,7 @@ static inline int bpf_map_attr_numa_node(const union bpf_attr *attr)
attr->numa_node : NUMA_NO_NODE;
}
-#else
+#else /* !CONFIG_BPF_SYSCALL */
static inline struct bpf_prog *bpf_prog_get(u32 ufd)
{
return ERR_PTR(-EOPNOTSUPP);
@@ -425,6 +432,28 @@ static inline void __dev_map_insert_ctx(struct bpf_map *map, u32 index)
static inline void __dev_map_flush(struct bpf_map *map)
{
}
+
+static inline
+struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key)
+{
+ return NULL;
+}
+
+static inline void __cpu_map_insert_ctx(struct bpf_map *map, u32 index)
+{
+}
+
+static inline void __cpu_map_flush(struct bpf_map *map)
+{
+}
+
+struct xdp_buff;
+static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu,
+ struct xdp_buff *xdp,
+ struct net_device *dev_rx)
+{
+ return 0;
+}
#endif /* CONFIG_BPF_SYSCALL */
#if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL)
diff --git a/include/trace/events/xdp.h b/include/trace/events/xdp.h
index 4e16c43fba10..eb2ece96c1a2 100644
--- a/include/trace/events/xdp.h
+++ b/include/trace/events/xdp.h
@@ -136,12 +136,18 @@ DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map_err,
__entry->map_id, __entry->map_index)
);
+#define devmap_ifindex(fwd, map) \
+ (!fwd ? 0 : \
+ (!map ? 0 : \
+ ((map->map_type == BPF_MAP_TYPE_DEVMAP) ? \
+ ((struct net_device *)fwd)->ifindex : 0)))
+
#define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx) \
- trace_xdp_redirect_map(dev, xdp, fwd ? fwd->ifindex : 0, \
+ trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map), \
0, map, idx)
#define _trace_xdp_redirect_map_err(dev, xdp, fwd, map, idx, err) \
- trace_xdp_redirect_map_err(dev, xdp, fwd ? fwd->ifindex : 0, \
+ trace_xdp_redirect_map_err(dev, xdp, devmap_ifindex(fwd, map), \
err, map, idx)
#endif /* _TRACE_XDP_H */
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index 34db22afcca2..bc989a9ae049 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -501,7 +501,7 @@ struct xdp_pkt {
/* Runs under RCU-read-side, plus in softirq under NAPI protection.
* Thus, safe percpu variable access.
*/
-int bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_pkt *xdp_pkt)
+static int bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_pkt *xdp_pkt)
{
struct xdp_bulk_queue *bq = this_cpu_ptr(rcpu->bulkq);
@@ -521,6 +521,26 @@ int bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_pkt *xdp_pkt)
return 0;
}
+int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
+ struct net_device *dev_rx)
+{
+ struct xdp_pkt *xdp_pkt;
+ int headroom;
+
+ /* For now this is just used as a void pointer to data_hard_start.
+ * Followup patch will generalize this.
+ */
+ xdp_pkt = xdp->data_hard_start;
+
+ /* Fake writing into xdp_pkt->data to measure overhead */
+ headroom = xdp->data - xdp->data_hard_start;
+ if (headroom < sizeof(*xdp_pkt))
+ xdp_pkt->data = xdp->data;
+
+ bq_enqueue(rcpu, xdp_pkt);
+ return 0;
+}
+
void __cpu_map_insert_ctx(struct bpf_map *map, u32 bit)
{
struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index d63fb96f114e..6da0e6c04df0 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1619,7 +1619,8 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id)
goto error;
break;
case BPF_FUNC_redirect_map:
- if (map->map_type != BPF_MAP_TYPE_DEVMAP)
+ if (map->map_type != BPF_MAP_TYPE_DEVMAP &&
+ map->map_type != BPF_MAP_TYPE_CPUMAP)
goto error;
break;
case BPF_FUNC_sk_redirect_map:
diff --git a/net/core/filter.c b/net/core/filter.c
index b7e8caa1e790..cc26ea62fc6d 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2525,10 +2525,36 @@ static int __bpf_tx_xdp(struct net_device *dev,
err = dev->netdev_ops->ndo_xdp_xmit(dev, xdp);
if (err)
return err;
- if (map)
+ dev->netdev_ops->ndo_xdp_flush(dev);
+ return 0;
+}
+
+static int __bpf_tx_xdp_map(struct net_device *dev_rx, void *fwd,
+ struct bpf_map *map,
+ struct xdp_buff *xdp,
+ u32 index)
+{
+ int err;
+
+ if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
+ struct net_device *dev = fwd;
+
+ if (!dev->netdev_ops->ndo_xdp_xmit)
+ return -EOPNOTSUPP;
+
+ err = dev->netdev_ops->ndo_xdp_xmit(dev, xdp);
+ if (err)
+ return err;
__dev_map_insert_ctx(map, index);
- else
- dev->netdev_ops->ndo_xdp_flush(dev);
+
+ } else if (map->map_type == BPF_MAP_TYPE_CPUMAP) {
+ struct bpf_cpu_map_entry *rcpu = fwd;
+
+ err = cpu_map_enqueue(rcpu, xdp, dev_rx);
+ if (err)
+ return err;
+ __cpu_map_insert_ctx(map, index);
+ }
return 0;
}
@@ -2538,11 +2564,33 @@ void xdp_do_flush_map(void)
struct bpf_map *map = ri->map_to_flush;
ri->map_to_flush = NULL;
- if (map)
- __dev_map_flush(map);
+ if (map) {
+ switch (map->map_type) {
+ case BPF_MAP_TYPE_DEVMAP:
+ __dev_map_flush(map);
+ break;
+ case BPF_MAP_TYPE_CPUMAP:
+ __cpu_map_flush(map);
+ break;
+ default:
+ break;
+ }
+ }
}
EXPORT_SYMBOL_GPL(xdp_do_flush_map);
+static void *__xdp_map_lookup_elem(struct bpf_map *map, u32 index)
+{
+ switch (map->map_type) {
+ case BPF_MAP_TYPE_DEVMAP:
+ return __dev_map_lookup_elem(map, index);
+ case BPF_MAP_TYPE_CPUMAP:
+ return __cpu_map_lookup_elem(map, index);
+ default:
+ return NULL;
+ }
+}
+
static inline bool xdp_map_invalid(const struct bpf_prog *xdp_prog,
unsigned long aux)
{
@@ -2555,8 +2603,8 @@ static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
unsigned long map_owner = ri->map_owner;
struct bpf_map *map = ri->map;
- struct net_device *fwd = NULL;
u32 index = ri->ifindex;
+ void *fwd = NULL;
int err;
ri->ifindex = 0;
@@ -2569,7 +2617,7 @@ static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
goto err;
}
- fwd = __dev_map_lookup_elem(map, index);
+ fwd = __xdp_map_lookup_elem(map, index);
if (!fwd) {
err = -EINVAL;
goto err;
@@ -2577,7 +2625,7 @@ static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
if (ri->map_to_flush && ri->map_to_flush != map)
xdp_do_flush_map();
- err = __bpf_tx_xdp(fwd, map, xdp, index);
+ err = __bpf_tx_xdp_map(dev, fwd, map, xdp, index);
if (unlikely(err))
goto err;
@@ -2619,54 +2667,88 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
}
EXPORT_SYMBOL_GPL(xdp_do_redirect);
-int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
- struct bpf_prog *xdp_prog)
+static int __xdp_generic_ok_fwd_dev(struct sk_buff *skb, struct net_device *fwd)
+{
+ unsigned int len;
+
+ if (unlikely(!(fwd->flags & IFF_UP)))
+ return -ENETDOWN;
+
+ len = fwd->mtu + fwd->hard_header_len + VLAN_HLEN;
+ if (skb->len > len)
+ return -EMSGSIZE;
+
+ return 0;
+}
+
+int xdp_do_generic_redirect_map(struct net_device *dev, struct sk_buff *skb,
+ struct bpf_prog *xdp_prog)
{
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
unsigned long map_owner = ri->map_owner;
struct bpf_map *map = ri->map;
struct net_device *fwd = NULL;
u32 index = ri->ifindex;
- unsigned int len;
int err = 0;
ri->ifindex = 0;
ri->map = NULL;
ri->map_owner = 0;
- if (map) {
- if (unlikely(xdp_map_invalid(xdp_prog, map_owner))) {
- err = -EFAULT;
- map = NULL;
- goto err;
- }
- fwd = __dev_map_lookup_elem(map, index);
- } else {
- fwd = dev_get_by_index_rcu(dev_net(dev), index);
+ if (unlikely(xdp_map_invalid(xdp_prog, map_owner))) {
+ err = -EFAULT;
+ map = NULL;
+ goto err;
}
+ fwd = __xdp_map_lookup_elem(map, index);
if (unlikely(!fwd)) {
err = -EINVAL;
goto err;
}
- if (unlikely(!(fwd->flags & IFF_UP))) {
- err = -ENETDOWN;
+ if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
+ if (unlikely((err = __xdp_generic_ok_fwd_dev(skb, fwd))))
+ goto err;
+ skb->dev = fwd;
+ } else {
+ /* TODO: Handle BPF_MAP_TYPE_CPUMAP */
+ err = -EBADRQC;
goto err;
}
- len = fwd->mtu + fwd->hard_header_len + VLAN_HLEN;
- if (skb->len > len) {
- err = -EMSGSIZE;
+ _trace_xdp_redirect_map(dev, xdp_prog, fwd, map, index);
+ return 0;
+err:
+ _trace_xdp_redirect_map_err(dev, xdp_prog, fwd, map, index, err);
+ return err;
+}
+
+int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
+ struct bpf_prog *xdp_prog)
+{
+ struct redirect_info *ri = this_cpu_ptr(&redirect_info);
+ u32 index = ri->ifindex;
+ struct net_device *fwd;
+ int err = 0;
+
+ if (ri->map)
+ return xdp_do_generic_redirect_map(dev, skb, xdp_prog);
+
+ ri->ifindex = 0;
+ fwd = dev_get_by_index_rcu(dev_net(dev), index);
+ if (unlikely(!fwd)) {
+ err = -EINVAL;
goto err;
}
+ if (unlikely((err = __xdp_generic_ok_fwd_dev(skb, fwd))))
+ goto err;
+
skb->dev = fwd;
- map ? _trace_xdp_redirect_map(dev, xdp_prog, fwd, map, index)
- : _trace_xdp_redirect(dev, xdp_prog, index);
+ _trace_xdp_redirect(dev, xdp_prog, index);
return 0;
err:
- map ? _trace_xdp_redirect_map_err(dev, xdp_prog, fwd, map, index, err)
- : _trace_xdp_redirect_err(dev, xdp_prog, index, err);
+ _trace_xdp_redirect_err(dev, xdp_prog, index, err);
return err;
}
EXPORT_SYMBOL_GPL(xdp_do_generic_redirect);
^ permalink raw reply related
* [net-next V7 PATCH 0/5] New bpf cpumap type for XDP_REDIRECT
From: Jesper Dangaard Brouer @ 2017-10-12 12:26 UTC (permalink / raw)
To: netdev
Cc: jakub.kicinski, Michael S. Tsirkin, pavel.odintsov, Jason Wang,
mchan, John Fastabend, peter.waskiewicz.jr,
Jesper Dangaard Brouer, ast, Daniel Borkmann, Alexei Starovoitov,
Andy Gospodarek
Introducing a new way to redirect XDP frames. Notice how no driver
changes are necessary given the design of XDP_REDIRECT.
In this V7, I've implemented a --stress-mode for the samples program,
which between each stats update, adds + removes CPUs from the map
concurrently with traffic. I did find and fix some concurrency issues
in the tear-down path, details in patch desc. The stress test have
now been running for 15 hours without any issues, while being bombarded
with 11.6 Mpps via pktgen_sample04_many_flows.sh.
This redirect map type is called 'cpumap', as it allows redirection
XDP frames to remote CPUs. The remote CPU will do the SKB allocation
and start the network stack invocation on that CPU.
This is a scalability and isolation mechanism, that allow separating
the early driver network XDP layer, from the rest of the netstack, and
assigning dedicated CPUs for this stage. The sysadm control/configure
the RX-CPU to NIC-RX queue (as usual) via procfs smp_affinity and how
many queues are configured via ethtool --set-channels. Benchmarks
show that a single CPU can handle approx 11Mpps. Thus, only assigning
two NIC RX-queues (and two CPUs) is sufficient for handling 10Gbit/s
wirespeed smallest packet 14.88Mpps. Reducing the number of queues
have the advantage that more packets being "bulk" available per hard
interrupt[1].
[1] https://www.netdevconf.org/2.1/papers/BusyPollingNextGen.pdf
Use-cases:
1. End-host based pre-filtering for DDoS mitigation. This is fast
enough to allow software to see and filter all packets wirespeed.
Thus, no packets getting silently dropped by hardware.
2. Given NIC HW unevenly distributes packets across RX queue, this
mechanism can be used for redistribution load across CPUs. This
usually happens when HW is unaware of a new protocol. This
resembles RPS (Receive Packet Steering), just faster, but with more
responsibility placed on the BPF program for correct steering.
3. Auto-scaling or power saving via only activating the appropriate
number of remote CPUs for handling the current load. The cpumap
tracepoints can function as a feedback loop for this purpose.
See individual patches for patchset-version changes.
Patchset V7 based on net-next at commit:
812b5ca7d376 ("Add a driver for Renesas uPD60620 and uPD60620A PHYs")
---
Jesper Dangaard Brouer (5):
bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP
bpf: XDP_REDIRECT enable use of cpumap
bpf: cpumap xdp_buff to skb conversion and allocation
bpf: cpumap add tracepoints
samples/bpf: add cpumap sample program xdp_redirect_cpu
include/linux/bpf.h | 31 +-
include/linux/bpf_types.h | 1
include/linux/netdevice.h | 1
include/trace/events/xdp.h | 80 ++++
include/uapi/linux/bpf.h | 1
kernel/bpf/Makefile | 1
kernel/bpf/cpumap.c | 702 +++++++++++++++++++++++++++++++++++
kernel/bpf/syscall.c | 8
kernel/bpf/verifier.c | 8
net/core/dev.c | 27 +
net/core/filter.c | 140 ++++++-
samples/bpf/Makefile | 4
samples/bpf/xdp_redirect_cpu_kern.c | 609 ++++++++++++++++++++++++++++++
samples/bpf/xdp_redirect_cpu_user.c | 697 +++++++++++++++++++++++++++++++++++
tools/include/uapi/linux/bpf.h | 1
15 files changed, 2277 insertions(+), 34 deletions(-)
create mode 100644 kernel/bpf/cpumap.c
create mode 100644 samples/bpf/xdp_redirect_cpu_kern.c
create mode 100644 samples/bpf/xdp_redirect_cpu_user.c
^ permalink raw reply
* Re: [PATCH] ravb: Consolidate clock handling
From: Geert Uytterhoeven @ 2017-10-12 12:20 UTC (permalink / raw)
To: Simon Horman
Cc: Geert Uytterhoeven, David S . Miller, Sergei Shtylyov,
Niklas Söderlund, netdev@vger.kernel.org, Linux-Renesas
In-Reply-To: <20171012095508.vjpqvq37474qp2cb@verge.net.au>
Hi Simon,
On Thu, Oct 12, 2017 at 11:55 AM, Simon Horman <horms@verge.net.au> wrote:
> On Thu, Oct 12, 2017 at 10:24:53AM +0200, Geert Uytterhoeven wrote:
>> The module clock is used for two purposes:
>> - Wake-on-LAN (WoL), which is optional,
>> - gPTP Timer Increment (GTI) configuration, which is mandatory.
>>
>> As the clock is needed for GTI configuration anyway, WoL is always
>> available. Hence remove duplication and repeated obtaining of the clock
>> by making GTI use the stored clock for WoL use.
>
> Hi Geert,
>
> I understand from the statements above that the clock must be present,
> but I'm most sure that I understand why that means that WoL is always
> available.
That refers to the part below: WoL was considered available iff the clock
is available.
@@ -2073,10 +2058,11 @@ static int ravb_probe(struct platform_device *pdev)
priv->chip_id = chip_id;
- /* Get clock, if not found that's OK but Wake-On-Lan is unavailable */
priv->clk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(priv->clk))
- priv->clk = NULL;
+ if (IS_ERR(priv->clk)) {
+ error = PTR_ERR(priv->clk);
+ goto out_release;
+ }
But the clock must always be available, else GTI configuration
would fail, and ravb initialization would return with an error.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply
* Re: [PATCH net-next v3 5/5] selinux: bpf: Add addtional check for bpf object file receive
From: Stephen Smalley @ 2017-10-12 12:25 UTC (permalink / raw)
To: Chenbo Feng
Cc: Daniel Borkmann, netdev, Chenbo Feng, linux-security-module,
SELinux, Alexei Starovoitov, Lorenzo Colitti
In-Reply-To: <CAMOXUJktUZ=s35gv9ttp0UYj9xn8Oqe8YkYtkkuhBBY+4wgExA@mail.gmail.com>
On Wed, 2017-10-11 at 13:43 -0700, Chenbo Feng via Selinux wrote:
> On Wed, Oct 11, 2017 at 5:54 AM, Stephen Smalley <sds@tycho.nsa.gov>
> wrote:
> > On Tue, 2017-10-10 at 17:09 -0700, Chenbo Feng wrote:
> > > From: Chenbo Feng <fengc@google.com>
> > >
> > > Introduce a bpf object related check when sending and receiving
> > > files
> > > through unix domain socket as well as binder. It checks if the
> > > receiving
> > > process have privilege to read/write the bpf map or use the bpf
> > > program.
> > > This check is necessary because the bpf maps and programs are
> > > using a
> > > anonymous inode as their shared inode so the normal way of
> > > checking
> > > the
> > > files and sockets when passing between processes cannot work
> > > properly
> > > on
> > > eBPF object. This check only works when the BPF_SYSCALL is
> > > configured.
> > > The information stored inside the file security struct is the
> > > same as
> > > the information in bpf object security struct.
> > >
> > > Signed-off-by: Chenbo Feng <fengc@google.com>
> > > ---
> > > include/linux/lsm_hooks.h | 17 ++++++++++
> > > include/linux/security.h | 9 ++++++
> > > kernel/bpf/syscall.c | 27 ++++++++++++++--
> > > security/security.c | 8 +++++
> > > security/selinux/hooks.c | 67
> > > +++++++++++++++++++++++++++++++++++++++
> > > security/selinux/include/objsec.h | 9 ++++++
> > > 6 files changed, 135 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/include/linux/lsm_hooks.h
> > > b/include/linux/lsm_hooks.h
> > > index 7161d8e7ee79..517dea60b87b 100644
> > > --- a/include/linux/lsm_hooks.h
> > > +++ b/include/linux/lsm_hooks.h
> > > @@ -1385,6 +1385,19 @@
> > > * @bpf_prog_free_security:
> > > * Clean up the security information stored inside bpf prog.
> > > *
> > > + * @bpf_map_file:
> > > + * When creating a bpf map fd, set up the file security
> > > information with
> > > + * the bpf security information stored in the map struct. So
> > > when the map
> > > + * fd is passed between processes, the security module can
> > > directly read
> > > + * the security information from file security struct rather
> > > than the bpf
> > > + * security struct.
> > > + *
> > > + * @bpf_prog_file:
> > > + * When creating a bpf prog fd, set up the file security
> > > information with
> > > + * the bpf security information stored in the prog struct. So
> > > when the prog
> > > + * fd is passed between processes, the security module can
> > > directly read
> > > + * the security information from file security struct rather
> > > than the bpf
> > > + * security struct.
> > > */
> > > union security_list_options {
> > > int (*binder_set_context_mgr)(struct task_struct *mgr);
> > > @@ -1726,6 +1739,8 @@ union security_list_options {
> > > void (*bpf_map_free_security)(struct bpf_map *map);
> > > int (*bpf_prog_alloc_security)(struct bpf_prog_aux *aux);
> > > void (*bpf_prog_free_security)(struct bpf_prog_aux *aux);
> > > + void (*bpf_map_file)(struct bpf_map *map, struct file
> > > *file);
> > > + void (*bpf_prog_file)(struct bpf_prog_aux *aux, struct file
> > > *file);
> > > #endif /* CONFIG_BPF_SYSCALL */
> > > };
> > >
> > > @@ -1954,6 +1969,8 @@ struct security_hook_heads {
> > > struct list_head bpf_map_free_security;
> > > struct list_head bpf_prog_alloc_security;
> > > struct list_head bpf_prog_free_security;
> > > + struct list_head bpf_map_file;
> > > + struct list_head bpf_prog_file;
> > > #endif /* CONFIG_BPF_SYSCALL */
> > > } __randomize_layout;
> > >
> > > diff --git a/include/linux/security.h b/include/linux/security.h
> > > index 18800b0911e5..57573b794e2d 100644
> > > --- a/include/linux/security.h
> > > +++ b/include/linux/security.h
> > > @@ -1740,6 +1740,8 @@ extern int security_bpf_map_alloc(struct
> > > bpf_map *map);
> > > extern void security_bpf_map_free(struct bpf_map *map);
> > > extern int security_bpf_prog_alloc(struct bpf_prog_aux *aux);
> > > extern void security_bpf_prog_free(struct bpf_prog_aux *aux);
> > > +extern void security_bpf_map_file(struct bpf_map *map, struct
> > > file
> > > *file);
> > > +extern void security_bpf_prog_file(struct bpf_prog_aux *aux,
> > > struct
> > > file *file);
> > > #else
> > > static inline int security_bpf(int cmd, union bpf_attr *attr,
> > > unsigned int size)
> > > @@ -1772,6 +1774,13 @@ static inline int
> > > security_bpf_prog_alloc(struct bpf_prog_aux *aux)
> > >
> > > static inline void security_bpf_prog_free(struct bpf_prog_aux
> > > *aux)
> > > { }
> > > +
> > > +static inline void security_bpf_map_file(struct bpf_map *map,
> > > struct
> > > file *file)
> > > +{ }
> > > +
> > > +static inline void security_bpf_prog_file(struct bpf_prog_aux
> > > *aux,
> > > + struct file *file)
> > > +{ }
> > > #endif /* CONFIG_SECURITY */
> > > #endif /* CONFIG_BPF_SYSCALL */
> > >
> > > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > > index 1cf31ddd7616..aee69e564c50 100644
> > > --- a/kernel/bpf/syscall.c
> > > +++ b/kernel/bpf/syscall.c
> > > @@ -324,11 +324,22 @@ static const struct file_operations
> > > bpf_map_fops = {
> > >
> > > int bpf_map_new_fd(struct bpf_map *map, int flags)
> > > {
> > > + int fd;
> > > + struct fd f;
> > > if (security_bpf_map(map, OPEN_FMODE(flags)))
> > > return -EPERM;
> > >
> > > - return anon_inode_getfd("bpf-map", &bpf_map_fops, map,
> > > + fd = anon_inode_getfd("bpf-map", &bpf_map_fops, map,
> > > flags | O_CLOEXEC);
> > > + if (fd < 0)
> > > + return fd;
> > > +
> > > + f = fdget(fd);
> > > + if (!f.file)
> > > + return -EBADF;
> >
> > This seems convoluted and unnecessarily inefficient, since
> > anon_inode_getfd() has the struct file and could have directly
> > returned
> > it instead of having to go through fdget() on a fd we just
> > installed.
> > Also, couldn't the fd->file mapping have changed underneath us
> > between
> > fd_install() and fdget()?
> > I would think it would be safer and more efficient to create an
> > anon_inode_getfdandfile() or similar interface and use that, so
> > that we
> > can just pass the file it set up to the hook. Obviously that would
> > need to be reviewed by the vfs folks.
> >
>
> Do you mean create a anonymous inode interface specifically for eBPF
> object? Is it okay that we add the hooks inside anon_inode_getfd and
> pass the file to the hook before fd install.
No, I meant to create a general helper, anon_inode_getfile(), that
returns the file and the fd to the caller, and then the BPF-specific
logic can stay in the BPF code.
However, if storing the bpf type in the file_security_struct is in fact
having a significant impact on per-file memory usage, then perhaps your
original approach of exporting and testing the fops was the right one,
albeit ugly.
> > > + security_bpf_map_file(map, f.file);
> > > + fdput(f);
> > > + return fd;
> > > }
> > >
> > > int bpf_get_file_flag(int flags)
> > > @@ -975,11 +986,23 @@ static const struct file_operations
> > > bpf_prog_fops = {
> > >
> > > int bpf_prog_new_fd(struct bpf_prog *prog)
> > > {
> > > + int fd;
> > > + struct fd f;
> > > +
> > > if (security_bpf_prog(prog))
> > > return -EPERM;
> > >
> > > - return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog,
> > > + fd = anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog,
> > > O_RDWR | O_CLOEXEC);
> > > + if (fd < 0)
> > > + return fd;
> > > +
> > > + f = fdget(fd);
> > > + if (!f.file)
> > > + return -EBADF;
> > > + security_bpf_prog_file(prog->aux, f.file);
> > > + fdput(f);
> > > + return fd;
> > > }
> > >
> > > static struct bpf_prog *____bpf_prog_get(struct fd f)
> > > diff --git a/security/security.c b/security/security.c
> > > index 1cd8526cb0b7..dacf649b8cfa 100644
> > > --- a/security/security.c
> > > +++ b/security/security.c
> > > @@ -1734,4 +1734,12 @@ void security_bpf_prog_free(struct
> > > bpf_prog_aux *aux)
> > > {
> > > call_void_hook(bpf_prog_free_security, aux);
> > > }
> > > +void security_bpf_map_file(struct bpf_map *map, struct file
> > > *file)
> > > +{
> > > + call_void_hook(bpf_map_file, map, file);
> > > +}
> > > +void security_bpf_prog_file(struct bpf_prog_aux *aux, struct
> > > file
> > > *file)
> > > +{
> > > + call_void_hook(bpf_prog_file, aux, file);
> > > +}
> > > #endif /* CONFIG_BPF_SYSCALL */
> > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > > index 94e473b9c884..0a6ef20513b0 100644
> > > --- a/security/selinux/hooks.c
> > > +++ b/security/selinux/hooks.c
> > > @@ -1815,6 +1815,10 @@ static inline int file_path_has_perm(const
> > > struct cred *cred,
> > > return inode_has_perm(cred, file_inode(file), av, &ad);
> > > }
> > >
> > > +#ifdef CONFIG_BPF_SYSCALL
> > > +static int bpf_file_check(struct file *file, u32 sid);
> > > +#endif
> > > +
> > > /* Check whether a task can use an open file descriptor to
> > > access an inode in a given way. Check access to the
> > > descriptor itself, and then use dentry_has_perm to
> > > @@ -1845,6 +1849,14 @@ static int file_has_perm(const struct cred
> > > *cred,
> > > goto out;
> > > }
> > >
> > > +#ifdef CONFIG_BPF_SYSCALL
> > > + if (fsec->bpf_type) {
> > > + rc = bpf_file_check(file, cred_sid(cred));
> > > + if (rc)
> > > + goto out;
> > > + }
> > > +#endif
> > > +
> > > /* av is zero if only checking access to the descriptor. */
> > > rc = 0;
> > > if (av)
> > > @@ -2165,6 +2177,14 @@ static int
> > > selinux_binder_transfer_file(struct
> > > task_struct *from,
> > > return rc;
> > > }
> > >
> > > +#ifdef CONFIG_BPF_SYSCALL
> > > + if (fsec->bpf_type) {
> > > + rc = bpf_file_check(file, sid);
> > > + if (rc)
> > > + return rc;
> > > + }
> > > +#endif
> > > +
> > > if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
> > > return 0;
> > >
> > > @@ -6288,6 +6308,33 @@ static u32 bpf_map_fmode_to_av(fmode_t
> > > fmode)
> > > return av;
> > > }
> > >
> > > +/* This function will check the file pass through unix socket or
> > > binder to see
> > > + * if it is a bpf related object. And apply correspinding checks
> > > on
> > > the bpf
> > > + * object based on the type. The bpf maps and programs, not like
> > > other files and
> > > + * socket, are using a shared anonymous inode inside the kernel
> > > as
> > > their inode.
> > > + * So checking that inode cannot identify if the process have
> > > privilege to
> > > + * access the bpf object and that's why we have to add this
> > > additional check in
> > > + * selinux_file_receive and selinux_binder_transfer_files.
> > > + */
> > > +static int bpf_file_check(struct file *file, u32 sid)
> > > +{
> > > + struct file_security_struct *fsec = file->f_security;
> > > + int ret;
> > > +
> > > + if (fsec->bpf_type == BPF_MAP) {
> > > + ret = avc_has_perm(sid, fsec->bpf_sid,
> > > SECCLASS_BPF,
> > > + bpf_map_fmode_to_av(file-
> > > > f_mode), NULL);
> > >
> > > + if (ret)
> > > + return ret;
> > > + } else if (fsec->bpf_type == BPF_PROG) {
> > > + ret = avc_has_perm(sid, fsec->bpf_sid,
> > > SECCLASS_BPF,
> > > + BPF__PROG_USE, NULL);
> > > + if (ret)
> > > + return ret;
> > > + }
> > > + return 0;
> > > +}
> > > +
> > > static int selinux_bpf_map(struct bpf_map *map, fmode_t fmode)
> > > {
> > > u32 sid = current_sid();
> > > @@ -6351,6 +6398,24 @@ static void selinux_bpf_prog_free(struct
> > > bpf_prog_aux *aux)
> > > aux->security = NULL;
> > > kfree(bpfsec);
> > > }
> > > +
> > > +static void selinux_bpf_map_file(struct bpf_map *map, struct
> > > file
> > > *file)
> > > +{
> > > + struct bpf_security_struct *bpfsec = map->security;
> > > + struct file_security_struct *fsec = file->f_security;
> > > +
> > > + fsec->bpf_type = BPF_MAP;
> > > + fsec->bpf_sid = bpfsec->sid;
> > > +}
> > > +
> > > +static void selinux_bpf_prog_file(struct bpf_prog_aux *aux,
> > > struct
> > > file *file)
> > > +{
> > > + struct bpf_security_struct *bpfsec = aux->security;
> > > + struct file_security_struct *fsec = file->f_security;
> > > +
> > > + fsec->bpf_type = BPF_PROG;
> > > + fsec->bpf_sid = bpfsec->sid;
> > > +}
> > > #endif
> > >
> > > static struct security_hook_list selinux_hooks[]
> > > __lsm_ro_after_init
> > > = {
> > > @@ -6581,6 +6646,8 @@ static struct security_hook_list
> > > selinux_hooks[] __lsm_ro_after_init = {
> > > LSM_HOOK_INIT(bpf_prog_alloc_security,
> > > selinux_bpf_prog_alloc),
> > > LSM_HOOK_INIT(bpf_map_free_security, selinux_bpf_map_free),
> > > LSM_HOOK_INIT(bpf_prog_free_security,
> > > selinux_bpf_prog_free),
> > > + LSM_HOOK_INIT(bpf_map_file, selinux_bpf_map_file),
> > > + LSM_HOOK_INIT(bpf_prog_file, selinux_bpf_prog_file),
> > > #endif
> > > };
> > >
> > > diff --git a/security/selinux/include/objsec.h
> > > b/security/selinux/include/objsec.h
> > > index 3d54468ce334..0162648761f9 100644
> > > --- a/security/selinux/include/objsec.h
> > > +++ b/security/selinux/include/objsec.h
> > > @@ -67,11 +67,20 @@ struct inode_security_struct {
> > > spinlock_t lock;
> > > };
> > >
> > > +enum bpf_obj_type {
> > > + BPF_MAP = 1,
> > > + BPF_PROG,
> > > +};
> > > +
> > > struct file_security_struct {
> > > u32 sid; /* SID of open file description */
> > > u32 fown_sid; /* SID of file owner (for
> > > SIGIO) */
> > > u32 isid; /* SID of inode at the time of file
> > > open */
> > > u32 pseqno; /* Policy seqno at the time of
> > > file open */
> > > +#ifdef CONFIG_BPF_SYSCALL
> > > + unsigned char bpf_type;
> > > + u32 bpf_sid;
> > > +#endif
> > > };
> >
> > Can you check how this impacts the size of the file_security_cache
> > objects, and thus the memory overhead imposed on all open files?
> >
> > If it is significant, do we need to cache the bpf_sid here or could
> > we
> > just store the bpf_type and then dereference the bpfsec if it is a
> > map
> > or prog?
> >
> > From proc/slabinfo I find the number of object and the object size
>
> grows a lot after adding this two field. I will try to dereference
> the
> bpfsec instead to see if it helps.
> > >
> > > struct superblock_security_struct {
^ permalink raw reply
* Re: [PATCH RFC 0/3] tun zerocopy stats
From: Jason Wang @ 2017-10-12 11:21 UTC (permalink / raw)
To: Willem de Bruijn
Cc: David Miller, Network Development, Michael S. Tsirkin,
Willem de Bruijn
In-Reply-To: <CAF=yD-++Vn6UbDm5q7_wpwx90Wt-Yia+g4ju_cJ+rX34tt7JPw@mail.gmail.com>
On 2017年10月12日 05:44, Willem de Bruijn wrote:
> On Tue, Oct 10, 2017 at 11:15 PM, Jason Wang <jasowang@redhat.com> wrote:
>>
>> On 2017年10月11日 03:11, Willem de Bruijn wrote:
>>> On Tue, Oct 10, 2017 at 1:39 PM, David Miller <davem@davemloft.net> wrote:
>>>> From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
>>>> Date: Tue, 10 Oct 2017 11:29:33 -0400
>>>>
>>>>> If there is a way to expose these stats through vhost_net directly,
>>>>> instead of through tun, that may be better. But I did not see a
>>>>> suitable interface. Perhaps debugfs.
>>>> Please don't use debugfs, thank you :-)
>>> Okay. I'll take a look at tracing for on-demand measurement.
>>
>> This reminds me a past series that adding tracepoints to vhost/net[1]. It
>> can count zero/datacopy independently and even contains a sample program to
>> show the stats.
> Interesting, thanks!
>
> For occasional evaluation, we can also use a bpf kprobe for the time being:
>
> bpf_program = """
> #include <uapi/linux/ptrace.h>
> #include <bcc/proto.h>
>
> BPF_ARRAY(count, u64, 2);
>
> void inc_counter(struct pt_regs *ctx) {
> bool success;
> int key;
> u64 *val;
>
> success = PT_REGS_PARM2(ctx);
> key = success ? 0 : 1;
> val = count.lookup(&key);
> if (val)
> lock_xadd(val, 1);
> }
> """
>
> b = bcc.BPF(text=bpf_program)
> b.attach_kprobe(event="vhost_zerocopy_callback", fn_name="inc_counter")
>
> time.sleep(5)
>
> print("vhost_zerocopy_callback: Y:%d N:%d" %
> (b["count"][ctypes.c_int(0)].value,
> b["count"][ctypes.c_int(1)].value))
Thanks for the tips, looks flexible.
^ permalink raw reply
* Re: [PATCH 00/10] staging/irda/net: Adjustments for several function implementations
From: Bjørn Mork @ 2017-10-12 11:17 UTC (permalink / raw)
To: SF Markus Elfring
Cc: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu, LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
Did you read drivers/staging/irda/TODO ?
There is no need to answer that. You already have. Thanks a lot for
your ever lasting invaluable contributions to /dev/null. Please
continue.
Bjørn
^ permalink raw reply
* Re: [PATCH net-next 1/1] net/smc: add SMC rendezvous protocol
From: Florian Westphal @ 2017-10-12 11:14 UTC (permalink / raw)
To: Ursula Braun
Cc: David Miller, netdev, linux-s390, jwi, schwidefsky,
heiko.carstens, raspl, hwippel
In-Reply-To: <b37b38df-cbb8-ca86-d460-9d3ec7acc2c6@linux.vnet.ibm.com>
Ursula Braun <ubraun@linux.vnet.ibm.com> wrote:
> On 10/11/2017 11:06 PM, David Miller wrote:
> > From: Ursula Braun <ubraun@linux.vnet.ibm.com>
> > Date: Tue, 10 Oct 2017 16:14:19 +0200
> >
> >> The goal of this patch is to leave common TCP code unmodified. Thus,
> >> it uses netfilter hooks to intercept TCP SYN and SYN/ACK
> >> packets. For outgoing packets originating from SMC sockets, the
> >> experimental option is added. For inbound packets destined for SMC
> >> sockets, the experimental option is checked.
> >
> > I think this really isn't going to pass.
> >
> > It's a user experience nightmare when the kernel inserts and
> > deletes filtering rules outside of what the user configures
> > on their system.
It depends if the hook is passive or not (i.e. mangles
payload/metadata or returns verdict other than NF_ACCEPT).
OUTPUT hook added here is not passive as it mangles tcp options.
> > This approach was also considerd for ipv6 ILA, and the same
> > pushback was given.
ahem.
net/ipv6/ila/ila_xlat.c: err = nf_register_net_hooks(net, ila_nf_hook_ops,
FWIW at least the input hook seems ok to me provided it would use
skb_header_pointer for tcp header access (there is no guarantee
tcp_hdr() works or that the tcp header has been sanity checked in any
way).
Perhaps its time to consider moving net/netfilter/core.c into net/core
and rename NF_HOOK to NET_HOOK?
^ permalink raw reply
* Re: [PATCH net-next] selftests: rtnetlink: add a small macsec test case
From: Florian Westphal @ 2017-10-12 10:52 UTC (permalink / raw)
To: Sabrina Dubroca; +Cc: Florian Westphal, netdev
In-Reply-To: <20171012101054.GA31183@bistromath.localdomain>
Sabrina Dubroca <sd@queasysnail.net> wrote:
> 2017-10-12, 11:11:22 +0200, Florian Westphal wrote:
> > Signed-off-by: Florian Westphal <fw@strlen.de>
>
> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Thanks for reviewing.
> Just a small detail: the "ip macsec" commands actually use genetlink
> and not rtnetlink.
Right, but it implements rtnl link ops so it ends up
interacting with rtnetlink too...
I also added sysfs-based change of device aliases to this script,
and I'm sure I will end up adding test cases that interact with
rtnetlink via ioctl, setsockopts and so on.
rtnl_lock() is all over the place so I think it makes sense to
cover as much callsites/call paths as possible even if the entry
point is not via rtnetlink socket.
^ permalink raw reply
* [PATCH 10/10] staging/irda/net: Use seq_puts() in four functions
From: SF Markus Elfring @ 2017-10-12 10:50 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: kernel-janitors, LKML
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 12 Oct 2017 11:08:36 +0200
Strings which did not contain a data format specification should be put
into a sequence. Thus use the corresponding function "seq_puts".
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/ircomm/ircomm_core.c | 8 ++++----
drivers/staging/irda/net/ircomm/ircomm_tty.c | 2 +-
drivers/staging/irda/net/irlan/irlan_common.c | 3 +--
drivers/staging/irda/net/irlmp.c | 2 +-
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/irda/net/ircomm/ircomm_core.c b/drivers/staging/irda/net/ircomm/ircomm_core.c
index 6c02fbf380bd..9bb2ff306470 100644
--- a/drivers/staging/irda/net/ircomm/ircomm_core.c
+++ b/drivers/staging/irda/net/ircomm/ircomm_core.c
@@ -530,13 +530,13 @@ static int ircomm_seq_show(struct seq_file *seq, void *v)
self->slsap_sel, self->dlsap_sel);
if(self->service_type & IRCOMM_3_WIRE_RAW)
- seq_printf(seq, " 3-wire-raw");
+ seq_puts(seq, " 3-wire-raw");
if(self->service_type & IRCOMM_3_WIRE)
- seq_printf(seq, " 3-wire");
+ seq_puts(seq, " 3-wire");
if(self->service_type & IRCOMM_9_WIRE)
- seq_printf(seq, " 9-wire");
+ seq_puts(seq, " 9-wire");
if(self->service_type & IRCOMM_CENTRONICS)
- seq_printf(seq, " Centronics");
+ seq_puts(seq, " Centronics");
seq_putc(seq, '\n');
return 0;
diff --git a/drivers/staging/irda/net/ircomm/ircomm_tty.c b/drivers/staging/irda/net/ircomm/ircomm_tty.c
index d1beec413fa3..dc7097576917 100644
--- a/drivers/staging/irda/net/ircomm/ircomm_tty.c
+++ b/drivers/staging/irda/net/ircomm/ircomm_tty.c
@@ -1174,7 +1174,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
seq_printf(m, "Port name: %s\n", self->settings.port_name);
- seq_printf(m, "DTE status:");
+ seq_puts(m, "DTE status:");
sep = ' ';
if (self->settings.dte & IRCOMM_RTS) {
seq_printf(m, "%cRTS", sep);
diff --git a/drivers/staging/irda/net/irlan/irlan_common.c b/drivers/staging/irda/net/irlan/irlan_common.c
index 481bbc2a4349..f4633d4dc390 100644
--- a/drivers/staging/irda/net/irlan/irlan_common.c
+++ b/drivers/staging/irda/net/irlan/irlan_common.c
@@ -1138,8 +1138,7 @@ static int irlan_seq_show(struct seq_file *seq, void *v)
seq_printf(seq,"media: %s\n",
irlan_media[self->media]);
- seq_printf(seq,"local filter:\n");
- seq_printf(seq,"remote filter: ");
+ seq_puts(seq, "local filter:\nremote filter: ");
irlan_print_filter(seq, self->client.filter_type);
seq_printf(seq,"tx busy: %s\n",
netif_queue_stopped(self->dev) ? "TRUE" : "FALSE");
diff --git a/drivers/staging/irda/net/irlmp.c b/drivers/staging/irda/net/irlmp.c
index 6a09cf621bd4..60a3dd7d6f49 100644
--- a/drivers/staging/irda/net/irlmp.c
+++ b/drivers/staging/irda/net/irlmp.c
@@ -1937,7 +1937,7 @@ static int irlmp_seq_show(struct seq_file *seq, void *v)
* the object spinlock, so we are safe. Jean II */
spin_lock(&lap->lsaps->hb_spinlock);
- seq_printf(seq, "\n Connected LSAPs:\n");
+ seq_puts(seq, "\n Connected LSAPs:\n");
for (self = (struct lsap_cb *) hashbin_get_first(lap->lsaps);
self;
self = (struct lsap_cb *)hashbin_get_next(lap->lsaps)) {
--
2.14.2
^ permalink raw reply related
* [PATCH 09/10] staging/irda/net: Combine some seq_printf() calls in two functions
From: SF Markus Elfring @ 2017-10-12 10:49 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 12 Oct 2017 08:58:38 +0200
Some data were printed into a sequence by separate function calls.
Print the same data by a single function call at each place instead.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/irlap.c | 9 ++++-----
drivers/staging/irda/net/irlmp.c | 6 ++----
2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/irda/net/irlap.c b/drivers/staging/irda/net/irlap.c
index 715cedab2f41..345c4eb55a59 100644
--- a/drivers/staging/irda/net/irlap.c
+++ b/drivers/staging/irda/net/irlap.c
@@ -1141,9 +1141,9 @@ static int irlap_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, "vr: %d ", self->vr);
seq_printf(seq, "va: %d\n", self->va);
- seq_printf(seq, " qos\tbps\tmaxtt\tdsize\twinsize\taddbofs\tmintt\tldisc\tcomp\n");
-
- seq_printf(seq, " tx\t%d\t",
+ seq_printf(seq,
+ " qos\tbps\tmaxtt\tdsize\twinsize\taddbofs\tmintt\tldisc\tcomp\n"
+ " tx\t%d\t",
self->qos_tx.baud_rate.value);
seq_printf(seq, "%d\t",
self->qos_tx.max_turn_time.value);
@@ -1157,9 +1157,8 @@ static int irlap_seq_show(struct seq_file *seq, void *v)
self->qos_tx.min_turn_time.value);
seq_printf(seq, "%d\t",
self->qos_tx.link_disc_time.value);
- seq_printf(seq, "\n");
- seq_printf(seq, " rx\t%d\t",
+ seq_printf(seq, "\n rx\t%d\t",
self->qos_rx.baud_rate.value);
seq_printf(seq, "%d\t",
self->qos_rx.max_turn_time.value);
diff --git a/drivers/staging/irda/net/irlmp.c b/drivers/staging/irda/net/irlmp.c
index 318660fbc094..6a09cf621bd4 100644
--- a/drivers/staging/irda/net/irlmp.c
+++ b/drivers/staging/irda/net/irlmp.c
@@ -1920,8 +1920,7 @@ static int irlmp_seq_show(struct seq_file *seq, void *v)
seq_printf(seq,
"slsap_sel: %#02x, dlsap_sel: %#02x, ",
self->slsap_sel, self->dlsap_sel);
- seq_printf(seq, "(%s)", self->notify.name);
- seq_printf(seq, "\n");
+ seq_printf(seq, "(%s)\n", self->notify.name);
} else if (iter->hashbin == irlmp->links) {
struct lap_cb *lap = v;
@@ -1930,9 +1929,8 @@ static int irlmp_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, "saddr: %#08x, daddr: %#08x, ",
lap->saddr, lap->daddr);
- seq_printf(seq, "num lsaps: %d",
+ seq_printf(seq, "num lsaps: %d\n",
HASHBIN_GET_SIZE(lap->lsaps));
- seq_printf(seq, "\n");
/* Careful for priority inversions here !
* All other uses of attrib spinlock are independent of
--
2.14.2
^ permalink raw reply related
* Re: [PATCH net-next 1/1] net/smc: add SMC rendezvous protocol
From: Ursula Braun @ 2017-10-12 10:48 UTC (permalink / raw)
To: David Miller
Cc: netdev, linux-s390, jwi, schwidefsky, heiko.carstens, raspl,
hwippel
In-Reply-To: <20171011.140652.272274136617199385.davem@davemloft.net>
On 10/11/2017 11:06 PM, David Miller wrote:
> From: Ursula Braun <ubraun@linux.vnet.ibm.com>
> Date: Tue, 10 Oct 2017 16:14:19 +0200
>
>> The goal of this patch is to leave common TCP code unmodified. Thus,
>> it uses netfilter hooks to intercept TCP SYN and SYN/ACK
>> packets. For outgoing packets originating from SMC sockets, the
>> experimental option is added. For inbound packets destined for SMC
>> sockets, the experimental option is checked.
>
> I think this really isn't going to pass.
>
> It's a user experience nightmare when the kernel inserts and
> deletes filtering rules outside of what the user configures
> on their system.
>
> This approach was also considerd for ipv6 ILA, and the same
> pushback was given.
>
> Why not add support for these new options as a normal TCP
> socket option based feature? Then normal userspace as well
> as the SMC stack can make use of it.
>
Do you mean a solution like
https://www.mail-archive.com/netdev@vger.kernel.org/msg71321.html
https://www.mail-archive.com/netdev@vger.kernel.org/msg71324.html
with a new smc_rendezvous TCP socket option as trigger?
^ permalink raw reply
* [PATCH 08/10] staging/irda/net: Use common error handling code in irias_new_object()
From: SF Markus Elfring @ 2017-10-12 10:48 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 12 Oct 2017 08:52:53 +0200
Add a jump target so that a bit of exception handling can be better
reused at the end of this function.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/irias_object.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/irda/net/irias_object.c b/drivers/staging/irda/net/irias_object.c
index 4c2c65e28836..0c89800d597d 100644
--- a/drivers/staging/irda/net/irias_object.c
+++ b/drivers/staging/irda/net/irias_object.c
@@ -54,10 +54,9 @@ struct ias_object *irias_new_object( char *name, int id)
obj->magic = IAS_OBJECT_MAGIC;
obj->name = kstrndup(name, IAS_MAX_CLASSNAME, GFP_ATOMIC);
- if (!obj->name) {
- kfree(obj);
- return NULL;
- }
+ if (!obj->name)
+ goto free_object;
+
obj->id = id;
/* Locking notes : the attrib spinlock has lower precendence
@@ -68,11 +67,14 @@ struct ias_object *irias_new_object( char *name, int id)
net_warn_ratelimited("%s(), Unable to allocate attribs!\n",
__func__);
kfree(obj->name);
- kfree(obj);
- return NULL;
+ goto free_object;
}
return obj;
+
+free_object:
+ kfree(obj);
+ return NULL;
}
EXPORT_SYMBOL(irias_new_object);
--
2.14.2
^ permalink raw reply related
* [PATCH 07/10] staging/irda/net: Delete an unnecessary variable initialisation in four functions
From: SF Markus Elfring @ 2017-10-12 10:47 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 11 Oct 2017 22:26:00 +0200
The variable "tx_skb" will eventually be set to an appropriate pointer
a bit later. Thus omit the explicit initialisation at the beginning.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/irlap_frame.c | 6 +++---
drivers/staging/irda/net/irttp.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/irda/net/irlap_frame.c b/drivers/staging/irda/net/irlap_frame.c
index 25ceb06efd58..16fe7f53fdb7 100644
--- a/drivers/staging/irda/net/irlap_frame.c
+++ b/drivers/staging/irda/net/irlap_frame.c
@@ -258,7 +258,7 @@ void irlap_send_ua_response_frame(struct irlap_cb *self, struct qos_info *qos)
*/
void irlap_send_dm_frame( struct irlap_cb *self)
{
- struct sk_buff *tx_skb = NULL;
+ struct sk_buff *tx_skb;
struct dm_frame *frame;
IRDA_ASSERT(self, return;);
@@ -288,7 +288,7 @@ void irlap_send_dm_frame( struct irlap_cb *self)
*/
void irlap_send_disc_frame(struct irlap_cb *self)
{
- struct sk_buff *tx_skb = NULL;
+ struct sk_buff *tx_skb;
struct disc_frame *frame;
IRDA_ASSERT(self, return;);
@@ -315,7 +315,7 @@ void irlap_send_disc_frame(struct irlap_cb *self)
void irlap_send_discovery_xid_frame(struct irlap_cb *self, int S, __u8 s,
__u8 command, discovery_t *discovery)
{
- struct sk_buff *tx_skb = NULL;
+ struct sk_buff *tx_skb;
struct xid_frame *frame;
__u32 bcast = BROADCAST;
__u8 *info;
diff --git a/drivers/staging/irda/net/irttp.c b/drivers/staging/irda/net/irttp.c
index 2adba87aeb68..bc612227cdc3 100644
--- a/drivers/staging/irda/net/irttp.c
+++ b/drivers/staging/irda/net/irttp.c
@@ -811,7 +811,7 @@ static void irttp_run_tx_queue(struct tsap_cb *self)
*/
static inline void irttp_give_credit(struct tsap_cb *self)
{
- struct sk_buff *tx_skb = NULL;
+ struct sk_buff *tx_skb;
unsigned long flags;
int n;
--
2.14.2
^ permalink raw reply related
* [PATCH 06/10] staging/irda/net: Delete an unnecessary variable initialisation in two functions
From: SF Markus Elfring @ 2017-10-12 10:46 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: kernel-janitors, LKML
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 11 Oct 2017 22:22:13 +0200
The local variable "tx_skb" will only be used in a single if branch
of these functions. Thus omit the explicit initialisation at the beginning.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/irlap_frame.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/irda/net/irlap_frame.c b/drivers/staging/irda/net/irlap_frame.c
index 5b8be5b9812e..25ceb06efd58 100644
--- a/drivers/staging/irda/net/irlap_frame.c
+++ b/drivers/staging/irda/net/irlap_frame.c
@@ -862,7 +862,7 @@ void irlap_send_data_primary_poll(struct irlap_cb *self, struct sk_buff *skb)
void irlap_send_data_secondary_final(struct irlap_cb *self,
struct sk_buff *skb)
{
- struct sk_buff *tx_skb = NULL;
+ struct sk_buff *tx_skb;
IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
@@ -922,7 +922,7 @@ void irlap_send_data_secondary_final(struct irlap_cb *self,
*/
void irlap_send_data_secondary(struct irlap_cb *self, struct sk_buff *skb)
{
- struct sk_buff *tx_skb = NULL;
+ struct sk_buff *tx_skb;
/* Is this reliable or unreliable data? */
if (skb->data[1] == I_FRAME) {
--
2.14.2
^ permalink raw reply related
* [PATCH 05/10] staging/irda/net: Delete an unnecessary variable initialisation in irlap_recv_discovery_xid_rsp()
From: SF Markus Elfring @ 2017-10-12 10:45 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 11 Oct 2017 22:20:22 +0200
The variable "discovery" will eventually be set to an appropriate pointer
a bit later. Thus omit the explicit initialisation at the beginning.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/irlap_frame.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/irda/net/irlap_frame.c b/drivers/staging/irda/net/irlap_frame.c
index 33259ed5f3cd..5b8be5b9812e 100644
--- a/drivers/staging/irda/net/irlap_frame.c
+++ b/drivers/staging/irda/net/irlap_frame.c
@@ -408,7 +408,7 @@ static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
struct irlap_info *info)
{
struct xid_frame *xid;
- discovery_t *discovery = NULL;
+ discovery_t *discovery;
__u8 *discovery_info;
char *text;
--
2.14.2
^ permalink raw reply related
* [PATCH 04/10] staging/irda/net: Delete an unnecessary variable initialisation in irlap_recv_discovery_xid_cmd()
From: SF Markus Elfring @ 2017-10-12 10:43 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 11 Oct 2017 22:18:34 +0200
The local variable "discovery" will only be used in a single if branch
of this function. Thus omit the explicit initialisation at the beginning.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/irlap_frame.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/irda/net/irlap_frame.c b/drivers/staging/irda/net/irlap_frame.c
index 94972db87951..33259ed5f3cd 100644
--- a/drivers/staging/irda/net/irlap_frame.c
+++ b/drivers/staging/irda/net/irlap_frame.c
@@ -481,7 +481,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
struct irlap_info *info)
{
struct xid_frame *xid;
- discovery_t *discovery = NULL;
+ discovery_t *discovery;
__u8 *discovery_info;
char *text;
--
2.14.2
^ permalink raw reply related
* [PATCH 03/10] staging/irda/net: Adjust 385 checks for null pointers
From: SF Markus Elfring @ 2017-10-12 10:42 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 11 Oct 2017 22:10:26 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
Use space characters at some places according to the Linux coding
style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/af_irda.c | 56 ++++++-------
drivers/staging/irda/net/discovery.c | 31 ++++---
drivers/staging/irda/net/irda_device.c | 2 +-
drivers/staging/irda/net/iriap.c | 61 +++++++-------
drivers/staging/irda/net/iriap_event.c | 34 ++++----
drivers/staging/irda/net/irias_object.c | 62 +++++++-------
drivers/staging/irda/net/irlap.c | 73 ++++++++--------
drivers/staging/irda/net/irlap_event.c | 77 +++++++++--------
drivers/staging/irda/net/irlap_frame.c | 51 +++++------
drivers/staging/irda/net/irlmp.c | 144 +++++++++++++++-----------------
drivers/staging/irda/net/irlmp_event.c | 50 ++++++-----
drivers/staging/irda/net/irlmp_frame.c | 24 +++---
drivers/staging/irda/net/irnetlink.c | 2 +-
drivers/staging/irda/net/irproc.c | 2 +-
drivers/staging/irda/net/irqueue.c | 32 +++----
drivers/staging/irda/net/irsysctl.c | 4 +-
drivers/staging/irda/net/irttp.c | 68 +++++++--------
drivers/staging/irda/net/parameters.c | 12 +--
drivers/staging/irda/net/qos.c | 20 ++---
drivers/staging/irda/net/timer.c | 12 +--
drivers/staging/irda/net/wrapper.c | 3 +-
21 files changed, 396 insertions(+), 424 deletions(-)
diff --git a/drivers/staging/irda/net/af_irda.c b/drivers/staging/irda/net/af_irda.c
index 23fa7c8b09a5..cb60b89053dd 100644
--- a/drivers/staging/irda/net/af_irda.c
+++ b/drivers/staging/irda/net/af_irda.c
@@ -121,7 +121,7 @@ static void irda_disconnect_indication(void *instance, void *sap,
dev_kfree_skb(skb);
sk = instance;
- if (sk == NULL) {
+ if (!sk) {
pr_debug("%s(%p) : BUG : sk is NULL\n",
__func__, self);
return;
@@ -182,7 +182,7 @@ static void irda_connect_confirm(void *instance, void *sap,
pr_debug("%s(%p)\n", __func__, self);
sk = instance;
- if (sk == NULL) {
+ if (!sk) {
dev_kfree_skb(skb);
return;
}
@@ -246,7 +246,7 @@ static void irda_connect_indication(void *instance, void *sap,
pr_debug("%s(%p)\n", __func__, self);
sk = instance;
- if (sk == NULL) {
+ if (!sk) {
dev_kfree_skb(skb);
return;
}
@@ -301,7 +301,7 @@ static void irda_connect_response(struct irda_sock *self)
struct sk_buff *skb;
skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER, GFP_KERNEL);
- if (skb == NULL) {
+ if (!skb) {
pr_debug("%s() Unable to allocate sk_buff!\n",
__func__);
return;
@@ -326,7 +326,7 @@ static void irda_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
self = instance;
sk = instance;
- BUG_ON(sk == NULL);
+ BUG_ON(!sk);
switch (flow) {
case FLOW_STOP:
@@ -434,7 +434,7 @@ static void irda_discovery_timeout(u_long priv)
struct irda_sock *self;
self = (struct irda_sock *) priv;
- BUG_ON(self == NULL);
+ BUG_ON(!self);
/* Nothing for the caller */
self->cachelog = NULL;
@@ -473,7 +473,7 @@ static int irda_open_tsap(struct irda_sock *self, __u8 tsap_sel, char *name)
self->tsap = irttp_open_tsap(tsap_sel, DEFAULT_INITIAL_CREDIT,
¬ify);
- if (self->tsap == NULL) {
+ if (!self->tsap) {
pr_debug("%s(), Unable to allocate TSAP!\n",
__func__);
return -ENOMEM;
@@ -507,7 +507,7 @@ static int irda_open_lsap(struct irda_sock *self, int pid)
strncpy(notify.name, "Ultra", NOTIFY_MAX_NAME);
self->lsap = irlmp_open_lsap(LSAP_CONNLESS, ¬ify, pid);
- if (self->lsap == NULL) {
+ if (!self->lsap) {
pr_debug("%s(), Unable to allocate LSAP!\n", __func__);
return -ENOMEM;
}
@@ -539,7 +539,7 @@ static int irda_find_lsap_sel(struct irda_sock *self, char *name)
self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
irda_getvalue_confirm);
- if(self->iriap == NULL)
+ if (!self->iriap)
return -ENOMEM;
/* Treat unexpected wakeup as disconnect */
@@ -625,7 +625,7 @@ static int irda_discover_daddr_and_lsap_sel(struct irda_sock *self, char *name)
discoveries = irlmp_get_discoveries(&number, self->mask.word,
self->nslots);
/* Check if the we got some results */
- if (discoveries == NULL)
+ if (!discoveries)
return -ENETUNREACH; /* No nodes discovered */
/*
@@ -801,7 +801,7 @@ static int irda_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
self->ias_obj = irias_new_object(addr->sir_name, jiffies);
err = -ENOMEM;
- if (self->ias_obj == NULL)
+ if (!self->ias_obj)
goto out;
err = irda_open_tsap(self, addr->sir_lsap_sel, addr->sir_name);
@@ -887,7 +887,7 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags,
newsk = newsock->sk;
err = -EIO;
- if (newsk == NULL)
+ if (!newsk)
goto out;
newsk->sk_state = TCP_ESTABLISHED;
@@ -1105,7 +1105,7 @@ static int irda_create(struct net *net, struct socket *sock, int protocol,
/* Allocate networking socket */
sk = sk_alloc(net, PF_IRDA, GFP_KERNEL, &irda_proto, kern);
- if (sk == NULL)
+ if (!sk)
return -ENOMEM;
self = irda_sk(sk);
@@ -1208,7 +1208,7 @@ static int irda_release(struct socket *sock)
{
struct sock *sk = sock->sk;
- if (sk == NULL)
+ if (!sk)
return 0;
lock_sock(sk);
@@ -1431,7 +1431,7 @@ static int irda_recvmsg_stream(struct socket *sock, struct msghdr *msg,
int chunk;
struct sk_buff *skb = skb_dequeue(&sk->sk_receive_queue);
- if (skb == NULL) {
+ if (!skb) {
DEFINE_WAIT(wait);
err = 0;
@@ -1454,7 +1454,7 @@ static int irda_recvmsg_stream(struct socket *sock, struct msghdr *msg,
err = sock_intr_errno(timeo);
else if (sk->sk_state != TCP_ESTABLISHED)
err = -ENOTCONN;
- else if (skb_peek(&sk->sk_receive_queue) == NULL)
+ else if (!skb_peek(&sk->sk_receive_queue))
/* Wait process until data arrives */
schedule();
@@ -1649,8 +1649,7 @@ static int irda_sendmsg_ultra(struct socket *sock, struct msghdr *msg,
} else {
/* Check that the socket is properly bound to an Ultra
* port. Jean II */
- if ((self->lsap == NULL) ||
- (sk->sk_state != TCP_ESTABLISHED)) {
+ if (!self->lsap || sk->sk_state != TCP_ESTABLISHED) {
pr_debug("%s(), socket not bound to Ultra PID.\n",
__func__);
err = -ENOTCONN;
@@ -1828,7 +1827,7 @@ static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
}
case SIOCGSTAMP:
- if (sk != NULL)
+ if (sk)
err = sock_get_timestamp(sk, (struct timeval __user *)arg);
break;
@@ -1913,7 +1912,7 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
* associated with this socket. This will workaround
* duplicated class name - Jean II */
if(ias_opt->irda_class_name[0] == '\0') {
- if(self->ias_obj == NULL) {
+ if (!self->ias_obj) {
kfree(ias_opt);
err = -EINVAL;
goto out;
@@ -1925,19 +1924,19 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
/* Only ROOT can mess with the global IAS database.
* Users can only add attributes to the object associated
* with the socket they own - Jean II */
- if((!capable(CAP_NET_ADMIN)) &&
- ((ias_obj == NULL) || (ias_obj != self->ias_obj))) {
+ if (!capable(CAP_NET_ADMIN) &&
+ (!ias_obj || ias_obj != self->ias_obj)) {
kfree(ias_opt);
err = -EPERM;
goto out;
}
/* If the object doesn't exist, create it */
- if(ias_obj == (struct ias_object *) NULL) {
+ if (!ias_obj) {
/* Create a new object */
ias_obj = irias_new_object(ias_opt->irda_class_name,
jiffies);
- if (ias_obj == NULL) {
+ if (!ias_obj) {
kfree(ias_opt);
err = -ENOMEM;
goto out;
@@ -2050,8 +2049,8 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
/* Only ROOT can mess with the global IAS database.
* Users can only del attributes from the object associated
* with the socket they own - Jean II */
- if((!capable(CAP_NET_ADMIN)) &&
- ((ias_obj == NULL) || (ias_obj != self->ias_obj))) {
+ if (!capable(CAP_NET_ADMIN) &&
+ (!ias_obj || ias_obj != self->ias_obj)) {
kfree(ias_opt);
err = -EPERM;
goto out;
@@ -2253,7 +2252,7 @@ static int irda_getsockopt(struct socket *sock, int level, int optname,
discoveries = irlmp_get_discoveries(&list.len, self->mask.word,
self->nslots);
/* Check if the we got some results */
- if (discoveries == NULL) {
+ if (!discoveries) {
err = -EAGAIN;
goto out; /* Didn't find any devices */
}
@@ -2404,8 +2403,7 @@ static int irda_getsockopt(struct socket *sock, int level, int optname,
self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
irda_getvalue_confirm);
-
- if (self->iriap == NULL) {
+ if (!self->iriap) {
kfree(ias_opt);
err = -ENOMEM;
goto out;
diff --git a/drivers/staging/irda/net/discovery.c b/drivers/staging/irda/net/discovery.c
index 1e54954a4081..7469d7c537a8 100644
--- a/drivers/staging/irda/net/discovery.c
+++ b/drivers/staging/irda/net/discovery.c
@@ -74,7 +74,7 @@ void irlmp_add_discovery(hashbin_t *cachelog, discovery_t *new)
* their device address between every discovery.
*/
discovery = (discovery_t *) hashbin_get_first(cachelog);
- while (discovery != NULL ) {
+ while (discovery) {
node = discovery;
/* Be sure to stay one item ahead */
@@ -118,7 +118,7 @@ void irlmp_add_discovery_log(hashbin_t *cachelog, hashbin_t *log)
* of the normal one.
*/
/* Well... It means that there was nobody out there - Jean II */
- if (log == NULL) {
+ if (!log) {
/* irlmp_start_discovery_timer(irlmp, 150); */
return;
}
@@ -129,7 +129,7 @@ void irlmp_add_discovery_log(hashbin_t *cachelog, hashbin_t *log)
* We just need to lock the global log in irlmp_add_discovery().
*/
discovery = (discovery_t *) hashbin_remove_first(log);
- while (discovery != NULL) {
+ while (discovery) {
irlmp_add_discovery(cachelog, discovery);
discovery = (discovery_t *) hashbin_remove_first(log);
@@ -156,11 +156,11 @@ void irlmp_expire_discoveries(hashbin_t *log, __u32 saddr, int force)
int n; /* Size of the full log */
int i = 0; /* How many we expired */
- IRDA_ASSERT(log != NULL, return;);
+ IRDA_ASSERT(log, return;);
spin_lock_irqsave(&log->hb_spinlock, flags);
discovery = (discovery_t *) hashbin_get_first(log);
- while (discovery != NULL) {
+ while (discovery) {
/* Be sure to be one item ahead */
curr = discovery;
discovery = (discovery_t *) hashbin_get_next(log);
@@ -175,7 +175,7 @@ void irlmp_expire_discoveries(hashbin_t *log, __u32 saddr, int force)
* we don't have anything to put in the log (we are
* quite picky), we can save a lot of overhead
* by not calling kmalloc. Jean II */
- if(buffer == NULL) {
+ if (!buffer) {
/* Create the client specific buffer */
n = HASHBIN_GET_SIZE(log);
buffer = kmalloc(n * sizeof(struct irda_device_info), GFP_ATOMIC);
@@ -203,7 +203,7 @@ void irlmp_expire_discoveries(hashbin_t *log, __u32 saddr, int force)
* don't care to be interrupted. - Jean II */
spin_unlock_irqrestore(&log->hb_spinlock, flags);
- if(buffer == NULL)
+ if (!buffer)
return;
/* Tell IrLMP and registered clients about it */
@@ -224,10 +224,10 @@ void irlmp_dump_discoveries(hashbin_t *log)
{
discovery_t *discovery;
- IRDA_ASSERT(log != NULL, return;);
+ IRDA_ASSERT(log, return;);
discovery = (discovery_t *) hashbin_get_first(log);
- while (discovery != NULL) {
+ while (discovery) {
pr_debug("Discovery:\n");
pr_debug(" daddr=%08x\n", discovery->data.daddr);
pr_debug(" saddr=%08x\n", discovery->data.saddr);
@@ -268,14 +268,14 @@ struct irda_device_info *irlmp_copy_discoveries(hashbin_t *log, int *pn,
int n; /* Size of the full log */
int i = 0; /* How many we picked */
- IRDA_ASSERT(pn != NULL, return NULL;);
- IRDA_ASSERT(log != NULL, return NULL;);
+ IRDA_ASSERT(pn, return NULL;);
+ IRDA_ASSERT(log, return NULL;);
/* Save spin lock */
spin_lock_irqsave(&log->hb_spinlock, flags);
discovery = (discovery_t *) hashbin_get_first(log);
- while (discovery != NULL) {
+ while (discovery) {
/* Mask out the ones we don't want :
* We want to match the discovery mask, and to get only
* the most recent one (unless we want old ones) */
@@ -287,7 +287,7 @@ struct irda_device_info *irlmp_copy_discoveries(hashbin_t *log, int *pn,
* we don't have anything to put in the log (we are
* quite picky), we can save a lot of overhead
* by not calling kmalloc. Jean II */
- if(buffer == NULL) {
+ if (!buffer) {
/* Create the client specific buffer */
n = HASHBIN_GET_SIZE(log);
buffer = kmalloc(n * sizeof(struct irda_device_info), GFP_ATOMIC);
@@ -320,7 +320,7 @@ static inline discovery_t *discovery_seq_idx(loff_t pos)
discovery_t *discovery;
for (discovery = (discovery_t *) hashbin_get_first(irlmp->cachelog);
- discovery != NULL;
+ discovery;
discovery = (discovery_t *) hashbin_get_next(irlmp->cachelog)) {
if (pos-- == 0)
break;
@@ -402,8 +402,7 @@ static const struct seq_operations discovery_seq_ops = {
static int discovery_seq_open(struct inode *inode, struct file *file)
{
- IRDA_ASSERT(irlmp != NULL, return -EINVAL;);
-
+ IRDA_ASSERT(irlmp, return -EINVAL;);
return seq_open(file, &discovery_seq_ops);
}
diff --git a/drivers/staging/irda/net/irda_device.c b/drivers/staging/irda/net/irda_device.c
index d33de8a8762a..f06bf24341f9 100644
--- a/drivers/staging/irda/net/irda_device.c
+++ b/drivers/staging/irda/net/irda_device.c
@@ -190,7 +190,7 @@ static int irda_task_kick(struct irda_task *task)
int count = 0;
int timeout;
- IRDA_ASSERT(task != NULL, return -1;);
+ IRDA_ASSERT(task, return -1;);
IRDA_ASSERT(task->magic == IRDA_TASK_MAGIC, return -1;);
/* Execute task until it's finished, or askes for a timeout */
diff --git a/drivers/staging/irda/net/iriap.c b/drivers/staging/irda/net/iriap.c
index 1138eaf5c682..2a6ffb468128 100644
--- a/drivers/staging/irda/net/iriap.c
+++ b/drivers/staging/irda/net/iriap.c
@@ -221,7 +221,7 @@ EXPORT_SYMBOL(iriap_open);
*/
static void __iriap_close(struct iriap_cb *self)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
del_timer(&self->watchdog_timer);
@@ -243,7 +243,7 @@ void iriap_close(struct iriap_cb *self)
{
struct iriap_cb *entry;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
if (self->lsap) {
@@ -274,7 +274,7 @@ static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
strcpy(notify.name, "IrIAS srv");
self->lsap = irlmp_open_lsap(slsap_sel, ¬ify, 0);
- if (self->lsap == NULL) {
+ if (!self->lsap) {
net_err_ratelimited("%s: Unable to allocated LSAP!\n",
__func__);
return -1;
@@ -301,10 +301,9 @@ static void iriap_disconnect_indication(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
-
- IRDA_ASSERT(iriap != NULL, return;);
+ IRDA_ASSERT(iriap, return;);
del_timer(&self->watchdog_timer);
@@ -340,11 +339,11 @@ static void iriap_disconnect_request(struct iriap_cb *self)
{
struct sk_buff *tx_skb;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
- if (tx_skb == NULL) {
+ if (!tx_skb) {
pr_debug("%s(), Could not allocate an sk_buff of length %d\n",
__func__, LMP_MAX_HEADER);
return;
@@ -372,7 +371,7 @@ int iriap_getvaluebyclass_request(struct iriap_cb *self,
int name_len, attr_len, skb_len;
__u8 *frame;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return -1;);
/* Client must supply the destination device address */
@@ -439,9 +438,9 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
__u8 *fp;
int n;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/* Initialize variables */
fp = skb->data;
@@ -551,9 +550,9 @@ static void iriap_getvaluebyclass_response(struct iriap_cb *self,
__be16 tmp_be16;
__u8 *fp;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
- IRDA_ASSERT(value != NULL, return;);
+ IRDA_ASSERT(value, return;);
IRDA_ASSERT(value->len <= 1024, return;);
/* Initialize variables */
@@ -643,9 +642,9 @@ static void iriap_getvaluebyclass_indication(struct iriap_cb *self,
__u8 *fp;
int n;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
fp = skb->data;
n = 1;
@@ -666,8 +665,7 @@ static void iriap_getvaluebyclass_indication(struct iriap_cb *self,
pr_debug("LM-IAS: Looking up %s: %s\n", name, attr);
obj = irias_find_object(name);
-
- if (obj == NULL) {
+ if (!obj) {
pr_debug("LM-IAS: Object %s not found\n", name);
iriap_getvaluebyclass_response(self, 0x1235, IAS_CLASS_UNKNOWN,
&irias_missing);
@@ -676,7 +674,7 @@ static void iriap_getvaluebyclass_indication(struct iriap_cb *self,
pr_debug("LM-IAS: found %s, id=%d\n", obj->name, obj->id);
attrib = irias_find_attrib(obj, attr);
- if (attrib == NULL) {
+ if (!attrib) {
pr_debug("LM-IAS: Attribute %s not found\n", attr);
iriap_getvaluebyclass_response(self, obj->id,
IAS_ATTRIB_UNKNOWN,
@@ -700,7 +698,7 @@ void iriap_send_ack(struct iriap_cb *self)
struct sk_buff *tx_skb;
__u8 *frame;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
tx_skb = alloc_skb(LMP_MAX_HEADER + 1, GFP_ATOMIC);
@@ -722,7 +720,7 @@ void iriap_connect_request(struct iriap_cb *self)
{
int ret;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
ret = irlmp_connect_request(self->lsap, LSAP_IAS,
@@ -749,9 +747,9 @@ static void iriap_connect_confirm(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
self->max_data_size = max_seg_size;
self->max_header_size = max_header_size;
@@ -779,8 +777,8 @@ static void iriap_connect_indication(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(skb != NULL, return;);
- IRDA_ASSERT(self != NULL, goto out;);
+ IRDA_ASSERT(skb, return;);
+ IRDA_ASSERT(self, goto out;);
IRDA_ASSERT(self->magic == IAS_MAGIC, goto out;);
/* Start new server */
@@ -825,8 +823,8 @@ static int iriap_data_indication(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(skb != NULL, return 0;);
- IRDA_ASSERT(self != NULL, goto out;);
+ IRDA_ASSERT(skb, return 0;);
+ IRDA_ASSERT(self, goto out;);
IRDA_ASSERT(self->magic == IAS_MAGIC, goto out;);
frame = skb->data;
@@ -914,9 +912,9 @@ void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
__u8 *fp;
__u8 opcode;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
fp = skb->data;
@@ -950,7 +948,7 @@ static void iriap_watchdog_timer_expired(void *data)
{
struct iriap_cb *self = (struct iriap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
/* iriap_close(self); */
@@ -1019,7 +1017,7 @@ static int irias_seq_show(struct seq_file *seq, void *v)
/* List all attributes for this object */
for (attrib = (struct ias_attrib *) hashbin_get_first(obj->attribs);
- attrib != NULL;
+ attrib;
attrib = (struct ias_attrib *) hashbin_get_next(obj->attribs)) {
IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC,
@@ -1069,8 +1067,7 @@ static const struct seq_operations irias_seq_ops = {
static int irias_seq_open(struct inode *inode, struct file *file)
{
- IRDA_ASSERT( irias_objects != NULL, return -EINVAL;);
-
+ IRDA_ASSERT(irias_objects, return -EINVAL;);
return seq_open(file, &irias_seq_ops);
}
diff --git a/drivers/staging/irda/net/iriap_event.c b/drivers/staging/irda/net/iriap_event.c
index e6098b2e048a..468e30172702 100644
--- a/drivers/staging/irda/net/iriap_event.c
+++ b/drivers/staging/irda/net/iriap_event.c
@@ -95,7 +95,7 @@ static void (*iriap_state[])(struct iriap_cb *self, IRIAP_EVENT event,
void iriap_next_client_state(struct iriap_cb *self, IRIAP_STATE state)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
self->client_state = state;
@@ -103,7 +103,7 @@ void iriap_next_client_state(struct iriap_cb *self, IRIAP_STATE state)
void iriap_next_call_state(struct iriap_cb *self, IRIAP_STATE state)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
self->call_state = state;
@@ -111,7 +111,7 @@ void iriap_next_call_state(struct iriap_cb *self, IRIAP_STATE state)
void iriap_next_server_state(struct iriap_cb *self, IRIAP_STATE state)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
self->server_state = state;
@@ -119,7 +119,7 @@ void iriap_next_server_state(struct iriap_cb *self, IRIAP_STATE state)
void iriap_next_r_connect_state(struct iriap_cb *self, IRIAP_STATE state)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
self->r_connect_state = state;
@@ -128,7 +128,7 @@ void iriap_next_r_connect_state(struct iriap_cb *self, IRIAP_STATE state)
void iriap_do_client_event(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
(*iriap_state[ self->client_state]) (self, event, skb);
@@ -137,7 +137,7 @@ void iriap_do_client_event(struct iriap_cb *self, IRIAP_EVENT event,
void iriap_do_call_event(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
(*iriap_state[ self->call_state]) (self, event, skb);
@@ -146,7 +146,7 @@ void iriap_do_call_event(struct iriap_cb *self, IRIAP_EVENT event,
void iriap_do_server_event(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
(*iriap_state[ self->server_state]) (self, event, skb);
@@ -155,7 +155,7 @@ void iriap_do_server_event(struct iriap_cb *self, IRIAP_EVENT event,
void iriap_do_r_connect_event(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
(*iriap_state[ self->r_connect_state]) (self, event, skb);
@@ -171,13 +171,13 @@ void iriap_do_r_connect_event(struct iriap_cb *self, IRIAP_EVENT event,
static void state_s_disconnect(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
switch (event) {
case IAP_CALL_REQUEST_GVBC:
iriap_next_client_state(self, S_CONNECTING);
- IRDA_ASSERT(self->request_skb == NULL, return;);
+ IRDA_ASSERT(!self->request_skb, return;);
/* Don't forget to refcount it -
* see iriap_getvaluebyclass_request(). */
skb_get(skb);
@@ -201,7 +201,7 @@ static void state_s_disconnect(struct iriap_cb *self, IRIAP_EVENT event,
static void state_s_connecting(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
switch (event) {
@@ -234,7 +234,7 @@ static void state_s_connecting(struct iriap_cb *self, IRIAP_EVENT event,
static void state_s_call(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
switch (event) {
case IAP_LM_DISCONNECT_INDICATION:
@@ -259,7 +259,7 @@ static void state_s_make_call(struct iriap_cb *self, IRIAP_EVENT event,
{
struct sk_buff *tx_skb;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
switch (event) {
case IAP_CALL_REQUEST:
@@ -297,7 +297,7 @@ static void state_s_calling(struct iriap_cb *self, IRIAP_EVENT event,
static void state_s_outstanding(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
switch (event) {
case IAP_RECV_F_LST:
@@ -368,7 +368,7 @@ static void state_r_disconnect(struct iriap_cb *self, IRIAP_EVENT event,
switch (event) {
case IAP_LM_CONNECT_INDICATION:
tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
- if (tx_skb == NULL)
+ if (!tx_skb)
return;
/* Reserve space for MUX_CONTROL and LAP header */
@@ -458,8 +458,8 @@ static void state_r_receiving(struct iriap_cb *self, IRIAP_EVENT event,
static void state_r_execute(struct iriap_cb *self, IRIAP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(skb != NULL, return;);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(skb, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
switch (event) {
diff --git a/drivers/staging/irda/net/irias_object.c b/drivers/staging/irda/net/irias_object.c
index 4db986b9d756..4c2c65e28836 100644
--- a/drivers/staging/irda/net/irias_object.c
+++ b/drivers/staging/irda/net/irias_object.c
@@ -64,8 +64,7 @@ struct ias_object *irias_new_object( char *name, int id)
* than the objects spinlock. Never grap the objects spinlock
* while holding any attrib spinlock (risk of deadlock). Jean II */
obj->attribs = hashbin_new(HB_LOCK);
-
- if (obj->attribs == NULL) {
+ if (!obj->attribs) {
net_warn_ratelimited("%s(), Unable to allocate attribs!\n",
__func__);
kfree(obj->name);
@@ -85,7 +84,7 @@ EXPORT_SYMBOL(irias_new_object);
*/
static void __irias_delete_attrib(struct ias_attrib *attrib)
{
- IRDA_ASSERT(attrib != NULL, return;);
+ IRDA_ASSERT(attrib, return;);
IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return;);
kfree(attrib->name);
@@ -98,7 +97,7 @@ static void __irias_delete_attrib(struct ias_attrib *attrib)
void __irias_delete_object(struct ias_object *obj)
{
- IRDA_ASSERT(obj != NULL, return;);
+ IRDA_ASSERT(obj, return;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
kfree(obj->name);
@@ -121,7 +120,7 @@ int irias_delete_object(struct ias_object *obj)
{
struct ias_object *node;
- IRDA_ASSERT(obj != NULL, return -1;);
+ IRDA_ASSERT(obj, return -1;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return -1;);
/* Remove from list */
@@ -149,9 +148,9 @@ int irias_delete_attrib(struct ias_object *obj, struct ias_attrib *attrib,
{
struct ias_attrib *node;
- IRDA_ASSERT(obj != NULL, return -1;);
+ IRDA_ASSERT(obj, return -1;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return -1;);
- IRDA_ASSERT(attrib != NULL, return -1;);
+ IRDA_ASSERT(attrib, return -1;);
/* Remove attribute from object */
node = hashbin_remove_this(obj->attribs, (irda_queue_t *) attrib);
@@ -181,7 +180,7 @@ int irias_delete_attrib(struct ias_object *obj, struct ias_attrib *attrib,
*/
void irias_insert_object(struct ias_object *obj)
{
- IRDA_ASSERT(obj != NULL, return;);
+ IRDA_ASSERT(obj, return;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
hashbin_insert(irias_objects, (irda_queue_t *) obj, 0, obj->name);
@@ -196,7 +195,7 @@ EXPORT_SYMBOL(irias_insert_object);
*/
struct ias_object *irias_find_object(char *name)
{
- IRDA_ASSERT(name != NULL, return NULL;);
+ IRDA_ASSERT(name, return NULL;);
/* Unsafe (locking), object might change */
return hashbin_lock_find(irias_objects, 0, name);
@@ -213,12 +212,12 @@ struct ias_attrib *irias_find_attrib(struct ias_object *obj, char *name)
{
struct ias_attrib *attrib;
- IRDA_ASSERT(obj != NULL, return NULL;);
+ IRDA_ASSERT(obj, return NULL;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return NULL;);
- IRDA_ASSERT(name != NULL, return NULL;);
+ IRDA_ASSERT(name, return NULL;);
attrib = hashbin_lock_find(obj->attribs, 0, name);
- if (attrib == NULL)
+ if (!attrib)
return NULL;
/* Unsafe (locking), attrib might change */
@@ -234,10 +233,9 @@ struct ias_attrib *irias_find_attrib(struct ias_object *obj, char *name)
static void irias_add_attrib(struct ias_object *obj, struct ias_attrib *attrib,
int owner)
{
- IRDA_ASSERT(obj != NULL, return;);
+ IRDA_ASSERT(obj, return;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
-
- IRDA_ASSERT(attrib != NULL, return;);
+ IRDA_ASSERT(attrib, return;);
IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return;);
/* Set if attrib is owned by kernel or user space */
@@ -261,7 +259,7 @@ int irias_object_change_attribute(char *obj_name, char *attrib_name,
/* Find object */
obj = hashbin_lock_find(irias_objects, 0, obj_name);
- if (obj == NULL) {
+ if (!obj) {
net_warn_ratelimited("%s: Unable to find object: %s\n",
__func__, obj_name);
return -1;
@@ -272,7 +270,7 @@ int irias_object_change_attribute(char *obj_name, char *attrib_name,
/* Find attribute */
attrib = hashbin_find(obj->attribs, 0, attrib_name);
- if (attrib == NULL) {
+ if (!attrib) {
net_warn_ratelimited("%s: Unable to find attribute: %s\n",
__func__, attrib_name);
spin_unlock_irqrestore(&obj->attribs->hb_spinlock, flags);
@@ -309,9 +307,9 @@ void irias_add_integer_attrib(struct ias_object *obj, char *name, int value,
{
struct ias_attrib *attrib;
- IRDA_ASSERT(obj != NULL, return;);
+ IRDA_ASSERT(obj, return;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
- IRDA_ASSERT(name != NULL, return;);
+ IRDA_ASSERT(name, return;);
attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
if (!attrib)
@@ -348,11 +346,10 @@ void irias_add_octseq_attrib(struct ias_object *obj, char *name, __u8 *octets,
{
struct ias_attrib *attrib;
- IRDA_ASSERT(obj != NULL, return;);
+ IRDA_ASSERT(obj, return;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
-
- IRDA_ASSERT(name != NULL, return;);
- IRDA_ASSERT(octets != NULL, return;);
+ IRDA_ASSERT(name, return;);
+ IRDA_ASSERT(octets, return;);
attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
if (!attrib)
@@ -387,11 +384,10 @@ void irias_add_string_attrib(struct ias_object *obj, char *name, char *value,
{
struct ias_attrib *attrib;
- IRDA_ASSERT(obj != NULL, return;);
+ IRDA_ASSERT(obj, return;);
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
-
- IRDA_ASSERT(name != NULL, return;);
- IRDA_ASSERT(value != NULL, return;);
+ IRDA_ASSERT(name, return;);
+ IRDA_ASSERT(value, return;);
attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
if (!attrib)
@@ -426,7 +422,7 @@ struct ias_value *irias_new_integer_value(int integer)
struct ias_value *value;
value = kzalloc(sizeof(*value), GFP_ATOMIC);
- if (value == NULL)
+ if (!value)
return NULL;
value->type = IAS_INTEGER;
@@ -449,7 +445,7 @@ struct ias_value *irias_new_string_value(char *string)
struct ias_value *value;
value = kzalloc(sizeof(*value), GFP_ATOMIC);
- if (value == NULL)
+ if (!value)
return NULL;
value->type = IAS_STRING;
@@ -477,7 +473,7 @@ struct ias_value *irias_new_octseq_value(__u8 *octseq , int len)
struct ias_value *value;
value = kzalloc(sizeof(*value), GFP_ATOMIC);
- if (value == NULL)
+ if (!value)
return NULL;
value->type = IAS_OCT_SEQ;
@@ -487,7 +483,7 @@ struct ias_value *irias_new_octseq_value(__u8 *octseq , int len)
value->len = len;
value->t.oct_seq = kmemdup(octseq, len, GFP_ATOMIC);
- if (value->t.oct_seq == NULL){
+ if (!value->t.oct_seq) {
kfree(value);
return NULL;
}
@@ -499,7 +495,7 @@ struct ias_value *irias_new_missing_value(void)
struct ias_value *value;
value = kzalloc(sizeof(*value), GFP_ATOMIC);
- if (value == NULL)
+ if (!value)
return NULL;
value->type = IAS_MISSING;
@@ -515,7 +511,7 @@ struct ias_value *irias_new_missing_value(void)
*/
void irias_delete_value(struct ias_value *value)
{
- IRDA_ASSERT(value != NULL, return;);
+ IRDA_ASSERT(value, return;);
switch (value->type) {
case IAS_INTEGER: /* Fallthrough */
diff --git a/drivers/staging/irda/net/irlap.c b/drivers/staging/irda/net/irlap.c
index 5dea721f44ac..715cedab2f41 100644
--- a/drivers/staging/irda/net/irlap.c
+++ b/drivers/staging/irda/net/irlap.c
@@ -82,7 +82,7 @@ int __init irlap_init(void)
/* Allocate master array */
irlap = hashbin_new(HB_LOCK);
- if (irlap == NULL) {
+ if (!irlap) {
net_err_ratelimited("%s: can't allocate irlap hashbin!\n",
__func__);
return -ENOMEM;
@@ -93,7 +93,7 @@ int __init irlap_init(void)
void irlap_cleanup(void)
{
- IRDA_ASSERT(irlap != NULL, return;);
+ IRDA_ASSERT(irlap, return;);
hashbin_delete(irlap, (FREE_FUNC) __irlap_close);
}
@@ -111,7 +111,7 @@ struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
/* Initialize the irlap structure. */
self = kzalloc(sizeof(*self), GFP_KERNEL);
- if (self == NULL)
+ if (!self)
return NULL;
self->magic = LAP_MAGIC;
@@ -120,11 +120,10 @@ struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
self->netdev = dev;
self->qos_dev = qos;
/* Copy hardware name */
- if(hw_name != NULL) {
+ if (hw_name)
strlcpy(self->hw_name, hw_name, sizeof(self->hw_name));
- } else {
+ else
self->hw_name[0] = '\0';
- }
/* FIXME: should we get our own field? */
dev->atalk_ptr = self;
@@ -179,7 +178,7 @@ EXPORT_SYMBOL(irlap_open);
*/
static void __irlap_close(struct irlap_cb *self)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Stop timers */
@@ -209,7 +208,7 @@ void irlap_close(struct irlap_cb *self)
{
struct irlap_cb *lap;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* We used to send a LAP_DISC_INDICATION here, but this was
@@ -238,7 +237,7 @@ EXPORT_SYMBOL(irlap_close);
*/
void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlap_init_qos_capabilities(self, NULL); /* No user QoS! */
@@ -270,7 +269,7 @@ void irlap_connect_request(struct irlap_cb *self, __u32 daddr,
{
pr_debug("%s(), daddr=0x%08x\n", __func__, daddr);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
self->daddr = daddr;
@@ -295,7 +294,7 @@ void irlap_connect_request(struct irlap_cb *self, __u32 daddr,
*/
void irlap_connect_confirm(struct irlap_cb *self, struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlmp_link_connect_confirm(self->notify.instance, &self->qos_tx, skb);
@@ -327,7 +326,7 @@ void irlap_data_indication(struct irlap_cb *self, struct sk_buff *skb,
void irlap_data_request(struct irlap_cb *self, struct sk_buff *skb,
int unreliable)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
IRDA_ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER),
@@ -372,7 +371,7 @@ void irlap_data_request(struct irlap_cb *self, struct sk_buff *skb,
#ifdef CONFIG_IRDA_ULTRA
void irlap_unitdata_request(struct irlap_cb *self, struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
IRDA_ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER),
@@ -399,9 +398,9 @@ void irlap_unitdata_request(struct irlap_cb *self, struct sk_buff *skb)
#ifdef CONFIG_IRDA_ULTRA
void irlap_unitdata_indication(struct irlap_cb *self, struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/* Hide LAP header from IrLMP layer */
skb_pull(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);
@@ -417,7 +416,7 @@ void irlap_unitdata_indication(struct irlap_cb *self, struct sk_buff *skb)
*/
void irlap_disconnect_request(struct irlap_cb *self)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Don't disconnect until all data frames are successfully sent */
@@ -452,7 +451,7 @@ void irlap_disconnect_indication(struct irlap_cb *self, LAP_REASON reason)
{
pr_debug("%s(), reason=%s\n", __func__, lap_reasons[reason]);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Flush queues */
@@ -486,9 +485,9 @@ void irlap_discovery_request(struct irlap_cb *self, discovery_t *discovery)
{
struct irlap_info info;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(discovery != NULL, return;);
+ IRDA_ASSERT(discovery, return;);
pr_debug("%s(), nslots = %d\n", __func__, discovery->nslots);
@@ -512,15 +511,14 @@ void irlap_discovery_request(struct irlap_cb *self, discovery_t *discovery)
/* Check if last discovery request finished in time, or if
* it was aborted due to the media busy flag. */
- if (self->discovery_log != NULL) {
+ if (self->discovery_log) {
hashbin_delete(self->discovery_log, (FREE_FUNC) kfree);
self->discovery_log = NULL;
}
/* All operations will occur at predictable time, no need to lock */
self->discovery_log = hashbin_new(HB_NOLOCK);
-
- if (self->discovery_log == NULL) {
+ if (!self->discovery_log) {
net_warn_ratelimited("%s(), Unable to allocate discovery log!\n",
__func__);
return;
@@ -546,10 +544,10 @@ void irlap_discovery_request(struct irlap_cb *self, discovery_t *discovery)
*/
void irlap_discovery_confirm(struct irlap_cb *self, hashbin_t *discovery_log)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(self->notify.instance != NULL, return;);
+ IRDA_ASSERT(self->notify.instance, return;);
/*
* Check for successful discovery, since we are then allowed to clear
@@ -577,11 +575,11 @@ void irlap_discovery_confirm(struct irlap_cb *self, hashbin_t *discovery_log)
*/
void irlap_discovery_indication(struct irlap_cb *self, discovery_t *discovery)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(discovery != NULL, return;);
+ IRDA_ASSERT(discovery, return;);
- IRDA_ASSERT(self->notify.instance != NULL, return;);
+ IRDA_ASSERT(self->notify.instance, return;);
/* A device is very likely to connect immediately after it performs
* a successful discovery. This means that in our case, we are much
@@ -621,7 +619,7 @@ void irlap_status_indication(struct irlap_cb *self, int quality_of_link)
*/
void irlap_reset_indication(struct irlap_cb *self)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
if (self->state == LAP_RESET_WAIT)
@@ -691,8 +689,7 @@ void irlap_update_nr_received(struct irlap_cb *self, int nr)
self->va = nr - 1;
} else {
/* Remove all acknowledged frames in current window */
- while ((skb_peek(&self->wx_list) != NULL) &&
- (((self->va+1) % 8) != nr))
+ while (skb_peek(&self->wx_list) && (((self->va + 1) % 8) != nr))
{
skb = skb_dequeue(&self->wx_list);
dev_kfree_skb(skb);
@@ -762,7 +759,7 @@ int irlap_validate_nr_received(struct irlap_cb *self, int nr)
*/
void irlap_initiate_connection_state(struct irlap_cb *self)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Next to send and next to receive */
@@ -818,7 +815,7 @@ void irlap_flush_all_queues(struct irlap_cb *self)
{
struct sk_buff* skb;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Free transmission queue */
@@ -845,7 +842,7 @@ static void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now)
pr_debug("%s(), setting speed to %d\n", __func__, speed);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
self->speed = speed;
@@ -870,9 +867,9 @@ static void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now)
static void irlap_init_qos_capabilities(struct irlap_cb *self,
struct qos_info *qos_user)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(self->netdev != NULL, return;);
+ IRDA_ASSERT(self->netdev, return;);
/* Start out with the maximum QoS support possible */
irda_init_max_qos_capabilies(&self->qos_rx);
@@ -916,7 +913,7 @@ static void irlap_init_qos_capabilities(struct irlap_cb *self,
*/
void irlap_apply_default_connection_parameters(struct irlap_cb *self)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* xbofs : Default value in NDM */
@@ -977,7 +974,7 @@ void irlap_apply_default_connection_parameters(struct irlap_cb *self)
*/
void irlap_apply_connection_parameters(struct irlap_cb *self, int now)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Set the negotiated xbofs value */
@@ -1189,7 +1186,7 @@ static const struct seq_operations irlap_seq_ops = {
static int irlap_seq_open(struct inode *inode, struct file *file)
{
- if (irlap == NULL)
+ if (!irlap)
return -EINVAL;
return seq_open_private(file, &irlap_seq_ops,
diff --git a/drivers/staging/irda/net/irlap_event.c b/drivers/staging/irda/net/irlap_event.c
index 0e1b4d79f745..22c44b010976 100644
--- a/drivers/staging/irda/net/irlap_event.c
+++ b/drivers/staging/irda/net/irlap_event.c
@@ -167,7 +167,7 @@ static void irlap_poll_timer_expired(void *data)
{
struct irlap_cb *self = (struct irlap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlap_do_event(self, POLL_TIMER_EXPIRED, NULL, NULL);
@@ -181,7 +181,7 @@ static void irlap_poll_timer_expired(void *data)
*/
static void irlap_start_poll_timer(struct irlap_cb *self, int timeout)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
#ifdef CONFIG_IRDA_FAST_RR
@@ -327,12 +327,12 @@ static int irlap_state_ndm(struct irlap_cb *self, IRLAP_EVENT event,
discovery_t *discovery_rsp;
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
case CONNECT_REQUEST:
- IRDA_ASSERT(self->netdev != NULL, return -1;);
+ IRDA_ASSERT(self->netdev, return -1;);
if (self->media_busy) {
/* Note : this will never happen, because we test
@@ -370,7 +370,7 @@ static int irlap_state_ndm(struct irlap_cb *self, IRLAP_EVENT event,
}
break;
case DISCOVERY_REQUEST:
- IRDA_ASSERT(info != NULL, return -1;);
+ IRDA_ASSERT(info, return -1;);
if (self->media_busy) {
pr_debug("%s(), DISCOVERY_REQUEST: media busy!\n",
@@ -396,7 +396,7 @@ static int irlap_state_ndm(struct irlap_cb *self, IRLAP_EVENT event,
irlap_next_state(self, LAP_QUERY);
break;
case RECV_DISCOVERY_XID_CMD:
- IRDA_ASSERT(info != NULL, return -1;);
+ IRDA_ASSERT(info, return -1;);
/* Assert that this is not the final slot */
if (info->s <= info->S) {
@@ -559,13 +559,13 @@ static int irlap_state_query(struct irlap_cb *self, IRLAP_EVENT event,
{
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
case RECV_DISCOVERY_XID_RSP:
- IRDA_ASSERT(info != NULL, return -1;);
- IRDA_ASSERT(info->discovery != NULL, return -1;);
+ IRDA_ASSERT(info, return -1;);
+ IRDA_ASSERT(info->discovery, return -1;);
pr_debug("%s(), daddr=%08x\n", __func__,
info->discovery->data.daddr);
@@ -595,7 +595,7 @@ static int irlap_state_query(struct irlap_cb *self, IRLAP_EVENT event,
* Jean II
*/
- IRDA_ASSERT(info != NULL, return -1;);
+ IRDA_ASSERT(info, return -1;);
pr_debug("%s(), Receiving discovery request (s = %d) while performing discovery :-(\n",
__func__, info->s);
@@ -671,7 +671,7 @@ static int irlap_state_reply(struct irlap_cb *self, IRLAP_EVENT event,
discovery_t *discovery_rsp;
int ret=0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
@@ -681,7 +681,7 @@ static int irlap_state_reply(struct irlap_cb *self, IRLAP_EVENT event,
irlap_next_state(self, LAP_NDM);
break;
case RECV_DISCOVERY_XID_CMD:
- IRDA_ASSERT(info != NULL, return -1;);
+ IRDA_ASSERT(info, return -1;);
/* Last frame? */
if (info->s == 0xff) {
del_timer(&self->query_timer);
@@ -738,14 +738,14 @@ static int irlap_state_conn(struct irlap_cb *self, IRLAP_EVENT event,
pr_debug("%s(), event=%s\n", __func__, irlap_event[event]);
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
case CONNECT_RESPONSE:
skb_pull(skb, sizeof(struct snrm_frame));
- IRDA_ASSERT(self->netdev != NULL, return -1;);
+ IRDA_ASSERT(self->netdev, return -1;);
irlap_qos_negotiate(self, skb);
@@ -830,7 +830,7 @@ static int irlap_state_setup(struct irlap_cb *self, IRLAP_EVENT event,
{
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
@@ -859,8 +859,8 @@ static int irlap_state_setup(struct irlap_cb *self, IRLAP_EVENT event,
case RECV_SNRM_CMD:
pr_debug("%s(), SNRM battle!\n", __func__);
- IRDA_ASSERT(skb != NULL, return 0;);
- IRDA_ASSERT(info != NULL, return 0;);
+ IRDA_ASSERT(skb, return 0;);
+ IRDA_ASSERT(info, return 0;);
/*
* The device with the largest device address wins the battle
@@ -870,7 +870,7 @@ static int irlap_state_setup(struct irlap_cb *self, IRLAP_EVENT event,
del_timer(&self->final_timer);
irlap_initiate_connection_state(self);
- IRDA_ASSERT(self->netdev != NULL, return -1;);
+ IRDA_ASSERT(self->netdev, return -1;);
skb_pull(skb, sizeof(struct snrm_frame));
@@ -906,7 +906,7 @@ static int irlap_state_setup(struct irlap_cb *self, IRLAP_EVENT event,
skb_pull(skb, sizeof(struct ua_frame));
- IRDA_ASSERT(self->netdev != NULL, return -1;);
+ IRDA_ASSERT(self->netdev, return -1;);
irlap_qos_negotiate(self, skb);
@@ -1013,9 +1013,9 @@ static int irlap_state_xmit_p(struct irlap_cb *self, IRLAP_EVENT event,
* end of the window and sending a extra RR.
* Note : (skb_next != NULL) <=> (skb_queue_len() > 0)
* Jean II */
- nextfit = ((skb_next != NULL) &&
- ((skb_next->len + skb->len) <=
- self->bytes_left));
+ nextfit = skb_next &&
+ (skb_next->len + skb->len)
+ <= self->bytes_left;
/*
* The current packet may not fit ! Because of test
@@ -1134,7 +1134,7 @@ static int irlap_state_pclose(struct irlap_cb *self, IRLAP_EVENT event,
{
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
@@ -1215,8 +1215,7 @@ static int irlap_state_nrm_p(struct irlap_cb *self, IRLAP_EVENT event,
*/
self->fast_RR = FALSE;
#endif /* CONFIG_IRDA_FAST_RR */
- IRDA_ASSERT( info != NULL, return -1;);
-
+ IRDA_ASSERT(info, return -1;);
ns_status = irlap_validate_ns_received(self, info->ns);
nr_status = irlap_validate_nr_received(self, info->nr);
@@ -1449,7 +1448,7 @@ static int irlap_state_nrm_p(struct irlap_cb *self, IRLAP_EVENT event,
/* Start poll timer */
irlap_start_poll_timer(self, self->poll_timeout);
} else if (ret == NR_UNEXPECTED) {
- IRDA_ASSERT(info != NULL, return -1;);
+ IRDA_ASSERT(info, return -1;);
/*
* Unexpected nr!
*/
@@ -1477,7 +1476,7 @@ static int irlap_state_nrm_p(struct irlap_cb *self, IRLAP_EVENT event,
}
break;
case RECV_RNR_RSP:
- IRDA_ASSERT(info != NULL, return -1;);
+ IRDA_ASSERT(info, return -1;);
/* Stop final timer */
del_timer(&self->final_timer);
@@ -1519,7 +1518,7 @@ static int irlap_state_nrm_p(struct irlap_cb *self, IRLAP_EVENT event,
/* N2 is the disconnect timer. Until we reach it, we retry */
if (self->retry_count < self->N2) {
- if (skb_peek(&self->wx_list) == NULL) {
+ if (!skb_peek(&self->wx_list)) {
/* Retry sending the pf bit to the secondary */
pr_debug("nrm_p: resending rr");
irlap_wait_min_turn_around(self, &self->qos_tx);
@@ -1603,7 +1602,7 @@ static int irlap_state_reset_wait(struct irlap_cb *self, IRLAP_EVENT event,
pr_debug("%s(), event = %s\n", __func__, irlap_event[event]);
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
@@ -1650,7 +1649,7 @@ static int irlap_state_reset(struct irlap_cb *self, IRLAP_EVENT event,
pr_debug("%s(), event = %s\n", __func__, irlap_event[event]);
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
@@ -1684,7 +1683,7 @@ static int irlap_state_reset(struct irlap_cb *self, IRLAP_EVENT event,
if (self->retry_count < 3) {
irlap_wait_min_turn_around(self, &self->qos_tx);
- IRDA_ASSERT(self->netdev != NULL, return -1;);
+ IRDA_ASSERT(self->netdev, return -1;);
irlap_send_snrm_frame(self, self->qos_dev);
self->retry_count++; /* Experimental!! */
@@ -1742,7 +1741,7 @@ static int irlap_state_xmit_s(struct irlap_cb *self, IRLAP_EVENT event,
pr_debug("%s(), event=%s\n", __func__, irlap_event[event]);
- IRDA_ASSERT(self != NULL, return -ENODEV;);
+ IRDA_ASSERT(self, return -ENODEV;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -EBADR;);
switch (event) {
@@ -1766,9 +1765,9 @@ static int irlap_state_xmit_s(struct irlap_cb *self, IRLAP_EVENT event,
* the current window (with respect to turnaround
* time). - Jean II */
skb_next = skb_peek(&self->txq);
- nextfit = ((skb_next != NULL) &&
- ((skb_next->len + skb->len) <=
- self->bytes_left));
+ nextfit = skb_next &&
+ (skb_next->len + skb->len)
+ <= self->bytes_left;
/*
* Test if we have transmitted more bytes over the
@@ -1864,7 +1863,7 @@ static int irlap_state_nrm_s(struct irlap_cb *self, IRLAP_EVENT event,
pr_debug("%s(), event=%s\n", __func__, irlap_event[event]);
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
switch (event) {
@@ -2215,7 +2214,7 @@ static int irlap_state_nrm_s(struct irlap_cb *self, IRLAP_EVENT event,
static int irlap_state_sclose(struct irlap_cb *self, IRLAP_EVENT event,
struct sk_buff *skb, struct irlap_info *info)
{
- IRDA_ASSERT(self != NULL, return -ENODEV;);
+ IRDA_ASSERT(self, return -ENODEV;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -EBADR;);
switch (event) {
@@ -2262,7 +2261,7 @@ static int irlap_state_sclose(struct irlap_cb *self, IRLAP_EVENT event,
/* IrLAP-1.1 p.82: in SCLOSE, basically any received frame
* with pf=1 shall restart the wd-timer and resend the rd:rsp
*/
- if (info != NULL && info->pf) {
+ if (info && info->pf) {
del_timer(&self->wd_timer);
irlap_wait_min_turn_around(self, &self->qos_tx);
irlap_send_rd_frame(self);
@@ -2287,7 +2286,7 @@ static int irlap_state_reset_check( struct irlap_cb *self, IRLAP_EVENT event,
pr_debug("%s(), event=%s\n", __func__, irlap_event[event]);
- IRDA_ASSERT(self != NULL, return -ENODEV;);
+ IRDA_ASSERT(self, return -ENODEV;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -EBADR;);
switch (event) {
diff --git a/drivers/staging/irda/net/irlap_frame.c b/drivers/staging/irda/net/irlap_frame.c
index d4d88a5d2976..94972db87951 100644
--- a/drivers/staging/irda/net/irlap_frame.c
+++ b/drivers/staging/irda/net/irlap_frame.c
@@ -123,7 +123,7 @@ void irlap_send_snrm_frame(struct irlap_cb *self, struct qos_info *qos)
struct snrm_frame *frame;
int ret;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Allocate frame */
@@ -218,7 +218,7 @@ void irlap_send_ua_response_frame(struct irlap_cb *self, struct qos_info *qos)
pr_debug("%s() <%ld>\n", __func__, jiffies);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Allocate frame */
@@ -261,7 +261,7 @@ void irlap_send_dm_frame( struct irlap_cb *self)
struct sk_buff *tx_skb = NULL;
struct dm_frame *frame;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
tx_skb = alloc_skb(sizeof(struct dm_frame), GFP_ATOMIC);
@@ -291,7 +291,7 @@ void irlap_send_disc_frame(struct irlap_cb *self)
struct sk_buff *tx_skb = NULL;
struct disc_frame *frame;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
tx_skb = alloc_skb(sizeof(struct disc_frame), GFP_ATOMIC);
@@ -323,9 +323,9 @@ void irlap_send_discovery_xid_frame(struct irlap_cb *self, int S, __u8 s,
pr_debug("%s(), s=%d, S=%d, command=%d\n", __func__,
s, S, command);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(discovery != NULL, return;);
+ IRDA_ASSERT(discovery, return;);
tx_skb = alloc_skb(sizeof(struct xid_frame) + IRLAP_DISCOVERY_INFO_LEN,
GFP_ATOMIC);
@@ -412,7 +412,7 @@ static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
__u8 *discovery_info;
char *text;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
if (!pskb_may_pull(skb, sizeof(struct xid_frame))) {
@@ -528,8 +528,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
*/
if (info->s == 0xff) {
/* Check if things are sane at this point... */
- if((discovery_info == NULL) ||
- !pskb_may_pull(skb, 3)) {
+ if (!discovery_info || !pskb_may_pull(skb, 3)) {
net_err_ratelimited("%s: discovery frame too short!\n",
__func__);
return;
@@ -732,9 +731,8 @@ void irlap_send_data_primary(struct irlap_cb *self, struct sk_buff *skb)
/* Copy buffer */
tx_skb = skb_clone(skb, GFP_ATOMIC);
- if (tx_skb == NULL) {
+ if (!tx_skb)
return;
- }
self->vs = (self->vs + 1) % 8;
self->ack_required = FALSE;
@@ -778,9 +776,8 @@ void irlap_send_data_primary_poll(struct irlap_cb *self, struct sk_buff *skb)
/* Copy buffer */
tx_skb = skb_clone(skb, GFP_ATOMIC);
- if (tx_skb == NULL) {
+ if (!tx_skb)
return;
- }
/*
* Set poll bit if necessary. We do this to the copied
@@ -867,9 +864,9 @@ void irlap_send_data_secondary_final(struct irlap_cb *self,
{
struct sk_buff *tx_skb = NULL;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/* Is this reliable or unreliable data? */
if (skb->data[1] == I_FRAME) {
@@ -888,9 +885,8 @@ void irlap_send_data_secondary_final(struct irlap_cb *self,
skb_queue_tail(&self->wx_list, skb);
tx_skb = skb_clone(skb, GFP_ATOMIC);
- if (tx_skb == NULL) {
+ if (!tx_skb)
return;
- }
tx_skb->data[1] |= PF_BIT;
@@ -945,9 +941,8 @@ void irlap_send_data_secondary(struct irlap_cb *self, struct sk_buff *skb)
skb_queue_tail(&self->wx_list, skb);
tx_skb = skb_clone(skb, GFP_ATOMIC);
- if (tx_skb == NULL) {
+ if (!tx_skb)
return;
- }
self->vs = (self->vs + 1) % 8;
self->ack_required = FALSE;
@@ -972,7 +967,7 @@ void irlap_resend_rejected_frames(struct irlap_cb *self, int command)
struct sk_buff *tx_skb;
struct sk_buff *skb;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Resend unacknowledged frame(s) */
@@ -1011,7 +1006,7 @@ void irlap_resend_rejected_frames(struct irlap_cb *self, int command)
pr_debug("%s(), sending additional frames!\n", __func__);
if (self->window > 0) {
skb = skb_dequeue( &self->txq);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/*
* If send window > 1 then send frame with pf
@@ -1034,12 +1029,12 @@ void irlap_resend_rejected_frame(struct irlap_cb *self, int command)
struct sk_buff *tx_skb;
struct sk_buff *skb;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
/* Resend unacknowledged frame(s) */
skb = skb_peek(&self->wx_list);
- if (skb != NULL) {
+ if (skb) {
irlap_wait_min_turn_around(self, &self->qos_tx);
/* We copy the skb to be retransmitted since we will have to
@@ -1071,9 +1066,9 @@ void irlap_resend_rejected_frame(struct irlap_cb *self, int command)
void irlap_send_ui_frame(struct irlap_cb *self, struct sk_buff *skb,
__u8 caddr, int command)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/* Insert connection address */
skb->data[0] = caddr | ((command) ? CMD_FRAME : 0);
@@ -1146,10 +1141,10 @@ static void irlap_recv_frmr_frame(struct irlap_cb *self, struct sk_buff *skb,
__u8 *frame;
int w, x, y, z;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
- IRDA_ASSERT(info != NULL, return;);
+ IRDA_ASSERT(skb, return;);
+ IRDA_ASSERT(info, return;);
if (!pskb_may_pull(skb, 4)) {
net_err_ratelimited("%s: frame too short!\n", __func__);
diff --git a/drivers/staging/irda/net/irlmp.c b/drivers/staging/irda/net/irlmp.c
index f075735e4b9b..318660fbc094 100644
--- a/drivers/staging/irda/net/irlmp.c
+++ b/drivers/staging/irda/net/irlmp.c
@@ -85,7 +85,7 @@ int __init irlmp_init(void)
{
/* Initialize the irlmp structure. */
irlmp = kzalloc( sizeof(struct irlmp_cb), GFP_KERNEL);
- if (irlmp == NULL)
+ if (!irlmp)
return -ENOMEM;
irlmp->magic = LMP_MAGIC;
@@ -95,14 +95,12 @@ int __init irlmp_init(void)
irlmp->links = hashbin_new(HB_LOCK);
irlmp->unconnected_lsaps = hashbin_new(HB_LOCK);
irlmp->cachelog = hashbin_new(HB_NOLOCK);
-
- if ((irlmp->clients == NULL) ||
- (irlmp->services == NULL) ||
- (irlmp->links == NULL) ||
- (irlmp->unconnected_lsaps == NULL) ||
- (irlmp->cachelog == NULL)) {
+ if (!irlmp->clients ||
+ !irlmp->services ||
+ !irlmp->links ||
+ !irlmp->unconnected_lsaps ||
+ !irlmp->cachelog)
return -ENOMEM;
- }
spin_lock_init(&irlmp->cachelog->hb_spinlock);
@@ -128,7 +126,7 @@ int __init irlmp_init(void)
void irlmp_cleanup(void)
{
/* Check for main structure */
- IRDA_ASSERT(irlmp != NULL, return;);
+ IRDA_ASSERT(irlmp, return;);
IRDA_ASSERT(irlmp->magic == LMP_MAGIC, return;);
del_timer(&irlmp->discovery_timer);
@@ -154,10 +152,10 @@ struct lsap_cb *irlmp_open_lsap(__u8 slsap_sel, notify_t *notify, __u8 pid)
{
struct lsap_cb *self;
- IRDA_ASSERT(notify != NULL, return NULL;);
- IRDA_ASSERT(irlmp != NULL, return NULL;);
+ IRDA_ASSERT(notify, return NULL;);
+ IRDA_ASSERT(irlmp, return NULL;);
IRDA_ASSERT(irlmp->magic == LMP_MAGIC, return NULL;);
- IRDA_ASSERT(notify->instance != NULL, return NULL;);
+ IRDA_ASSERT(notify->instance, return NULL;);
/* Does the client care which Source LSAP selector it gets? */
if (slsap_sel == LSAP_ANY) {
@@ -169,7 +167,7 @@ struct lsap_cb *irlmp_open_lsap(__u8 slsap_sel, notify_t *notify, __u8 pid)
/* Allocate new instance of a LSAP connection */
self = kzalloc(sizeof(*self), GFP_ATOMIC);
- if (self == NULL)
+ if (!self)
return NULL;
self->magic = LMP_LSAP_MAGIC;
@@ -206,7 +204,7 @@ EXPORT_SYMBOL(irlmp_open_lsap);
*/
static void __irlmp_close_lsap(struct lsap_cb *self)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
/*
@@ -232,7 +230,7 @@ void irlmp_close_lsap(struct lsap_cb *self)
struct lap_cb *lap;
struct lsap_cb *lsap = NULL;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
/*
@@ -283,15 +281,15 @@ void irlmp_register_link(struct irlap_cb *irlap, __u32 saddr, notify_t *notify)
{
struct lap_cb *lap;
- IRDA_ASSERT(irlmp != NULL, return;);
+ IRDA_ASSERT(irlmp, return;);
IRDA_ASSERT(irlmp->magic == LMP_MAGIC, return;);
- IRDA_ASSERT(notify != NULL, return;);
+ IRDA_ASSERT(notify, return;);
/*
* Allocate new instance of a LSAP connection
*/
lap = kzalloc(sizeof(*lap), GFP_KERNEL);
- if (lap == NULL)
+ if (!lap)
return;
lap->irlap = irlap;
@@ -302,7 +300,7 @@ void irlmp_register_link(struct irlap_cb *irlap, __u32 saddr, notify_t *notify)
lap->cache.valid = FALSE;
#endif
lap->lsaps = hashbin_new(HB_LOCK);
- if (lap->lsaps == NULL) {
+ if (!lap->lsaps) {
net_warn_ratelimited("%s(), unable to kmalloc lsaps\n",
__func__);
kfree(lap);
@@ -374,7 +372,7 @@ int irlmp_connect_request(struct lsap_cb *self, __u8 dlsap_sel,
struct lsap_cb *lsap;
int ret;
- IRDA_ASSERT(self != NULL, return -EBADR;);
+ IRDA_ASSERT(self, return -EBADR;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -EBADR;);
pr_debug("%s(), slsap_sel=%02x, dlsap_sel=%02x, saddr=%08x, daddr=%08x\n",
@@ -392,7 +390,7 @@ int irlmp_connect_request(struct lsap_cb *self, __u8 dlsap_sel,
}
/* Any userdata? */
- if (tx_skb == NULL) {
+ if (!tx_skb) {
tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
if (!tx_skb)
return -ENOMEM;
@@ -434,7 +432,7 @@ int irlmp_connect_request(struct lsap_cb *self, __u8 dlsap_sel,
spin_unlock_irqrestore(&irlmp->cachelog->hb_spinlock, flags);
}
lap = hashbin_lock_find(irlmp->links, saddr, NULL);
- if (lap == NULL) {
+ if (!lap) {
pr_debug("%s(), Unable to find a usable link!\n", __func__);
ret = -EHOSTUNREACH;
goto err;
@@ -471,9 +469,9 @@ int irlmp_connect_request(struct lsap_cb *self, __u8 dlsap_sel,
*/
lsap = hashbin_remove(irlmp->unconnected_lsaps, (long) self, NULL);
- IRDA_ASSERT(lsap != NULL, return -1;);
+ IRDA_ASSERT(lsap, return -1;);
IRDA_ASSERT(lsap->magic == LMP_LSAP_MAGIC, return -1;);
- IRDA_ASSERT(lsap->lap != NULL, return -1;);
+ IRDA_ASSERT(lsap->lap, return -1;);
IRDA_ASSERT(lsap->lap->magic == LMP_LAP_MAGIC, return -1;);
hashbin_insert(self->lap->lsaps, (irda_queue_t *) self, (long) self,
@@ -514,10 +512,10 @@ void irlmp_connect_indication(struct lsap_cb *self, struct sk_buff *skb)
int lap_header_size;
int max_header_size;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
- IRDA_ASSERT(self->lap != NULL, return;);
+ IRDA_ASSERT(skb, return;);
+ IRDA_ASSERT(self->lap, return;);
pr_debug("%s(), slsap_sel=%02x, dlsap_sel=%02x\n",
__func__, self->slsap_sel, self->dlsap_sel);
@@ -553,9 +551,9 @@ void irlmp_connect_indication(struct lsap_cb *self, struct sk_buff *skb)
*/
int irlmp_connect_response(struct lsap_cb *self, struct sk_buff *userdata)
{
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
- IRDA_ASSERT(userdata != NULL, return -1;);
+ IRDA_ASSERT(userdata, return -1;);
/* We set the connected bit and move the lsap to the connected list
* in the state machine itself. Jean II */
@@ -587,10 +585,10 @@ void irlmp_connect_confirm(struct lsap_cb *self, struct sk_buff *skb)
int lap_header_size;
int max_seg_size;
- IRDA_ASSERT(skb != NULL, return;);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(skb, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
- IRDA_ASSERT(self->lap != NULL, return;);
+ IRDA_ASSERT(self->lap, return;);
self->qos = *self->lap->qos;
@@ -630,7 +628,7 @@ struct lsap_cb *irlmp_dup(struct lsap_cb *orig, void *instance)
/* Only allowed to duplicate unconnected LSAP's, and only LSAPs
* that have received a connect indication. Jean II */
if ((!hashbin_find(irlmp->unconnected_lsaps, (long) orig, NULL)) ||
- (orig->lap == NULL)) {
+ (!orig->lap)) {
pr_debug("%s(), invalid LSAP (wrong state)\n",
__func__);
spin_unlock_irqrestore(&irlmp->unconnected_lsaps->hb_spinlock,
@@ -677,9 +675,9 @@ int irlmp_disconnect_request(struct lsap_cb *self, struct sk_buff *userdata)
{
struct lsap_cb *lsap;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
- IRDA_ASSERT(userdata != NULL, return -1;);
+ IRDA_ASSERT(userdata, return -1;);
/* Already disconnected ?
* There is a race condition between irlmp_disconnect_indication()
@@ -706,16 +704,16 @@ int irlmp_disconnect_request(struct lsap_cb *self, struct sk_buff *userdata)
* Remove LSAP from list of connected LSAPs for the particular link
* and insert it into the list of unconnected LSAPs
*/
- IRDA_ASSERT(self->lap != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
IRDA_ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
- IRDA_ASSERT(self->lap->lsaps != NULL, return -1;);
+ IRDA_ASSERT(self->lap->lsaps, return -1;);
lsap = hashbin_remove(self->lap->lsaps, (long) self, NULL);
#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
self->lap->cache.valid = FALSE;
#endif
- IRDA_ASSERT(lsap != NULL, return -1;);
+ IRDA_ASSERT(lsap, return -1;);
IRDA_ASSERT(lsap->magic == LMP_LSAP_MAGIC, return -1;);
IRDA_ASSERT(lsap == self, return -1;);
@@ -742,7 +740,7 @@ void irlmp_disconnect_indication(struct lsap_cb *self, LM_REASON reason,
pr_debug("%s(), reason=%s [%d]\n", __func__,
irlmp_reason_str(reason), reason);
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
pr_debug("%s(), slsap_sel=%02x, dlsap_sel=%02x\n",
@@ -760,15 +758,15 @@ void irlmp_disconnect_indication(struct lsap_cb *self, LM_REASON reason,
/*
* Remove association between this LSAP and the link it used
*/
- IRDA_ASSERT(self->lap != NULL, return;);
- IRDA_ASSERT(self->lap->lsaps != NULL, return;);
+ IRDA_ASSERT(self->lap, return;);
+ IRDA_ASSERT(self->lap->lsaps, return;);
lsap = hashbin_remove(self->lap->lsaps, (long) self, NULL);
#ifdef CONFIG_IRDA_CACHE_LAST_LSAP
self->lap->cache.valid = FALSE;
#endif
- IRDA_ASSERT(lsap != NULL, return;);
+ IRDA_ASSERT(lsap, return;);
IRDA_ASSERT(lsap == self, return;);
hashbin_insert(irlmp->unconnected_lsaps, (irda_queue_t *) lsap,
(long) lsap, NULL);
@@ -812,7 +810,7 @@ void irlmp_do_expiry(void)
* to work properly. - Jean II
*/
lap = (struct lap_cb *) hashbin_get_first(irlmp->links);
- while (lap != NULL) {
+ while (lap) {
IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, return;);
if (lap->lap_state == LAP_STANDBY) {
@@ -862,7 +860,7 @@ void irlmp_do_discovery(int nslots)
* Try to send discovery packets on all links
*/
lap = (struct lap_cb *) hashbin_get_first(irlmp->links);
- while (lap != NULL) {
+ while (lap) {
IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, return;);
if (lap->lap_state == LAP_STANDBY) {
@@ -983,7 +981,7 @@ irlmp_notify_client(irlmp_client_t *client,
client->hint_mask.word,
(mode == DISCOVERY_LOG));
/* Check if the we got some results */
- if (discoveries == NULL)
+ if (!discoveries)
return; /* No nodes discovered */
/* Pass all entries to the listener */
@@ -1006,7 +1004,7 @@ void irlmp_discovery_confirm(hashbin_t *log, DISCOVERY_MODE mode)
irlmp_client_t *client;
irlmp_client_t *client_next;
- IRDA_ASSERT(log != NULL, return;);
+ IRDA_ASSERT(log, return;);
if (!(HASHBIN_GET_SIZE(log)))
return;
@@ -1039,7 +1037,7 @@ void irlmp_discovery_expiry(discinfo_t *expiries, int number)
irlmp_client_t *client_next;
int i;
- IRDA_ASSERT(expiries != NULL, return;);
+ IRDA_ASSERT(expiries, return;);
/* For each client - notify callback may touch client list */
client = (irlmp_client_t *) hashbin_get_first(irlmp->clients);
@@ -1071,7 +1069,7 @@ void irlmp_discovery_expiry(discinfo_t *expiries, int number)
*/
discovery_t *irlmp_get_discovery_response(void)
{
- IRDA_ASSERT(irlmp != NULL, return NULL;);
+ IRDA_ASSERT(irlmp, return NULL;);
put_unaligned(irlmp->hints.word, (__u16 *)irlmp->discovery_rsp.data.hints);
@@ -1106,7 +1104,7 @@ int irlmp_data_request(struct lsap_cb *self, struct sk_buff *userdata)
{
int ret;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
/* Make room for MUX header */
@@ -1147,7 +1145,7 @@ int irlmp_udata_request(struct lsap_cb *self, struct sk_buff *userdata)
{
int ret;
- IRDA_ASSERT(userdata != NULL, return -1;);
+ IRDA_ASSERT(userdata, return -1;);
/* Make room for MUX header */
IRDA_ASSERT(skb_headroom(userdata) >= LMP_HEADER, return -1;);
@@ -1169,9 +1167,9 @@ int irlmp_udata_request(struct lsap_cb *self, struct sk_buff *userdata)
*/
void irlmp_udata_indication(struct lsap_cb *self, struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/* Hide LMP header from layer above */
skb_pull(skb, LMP_HEADER);
@@ -1194,7 +1192,7 @@ int irlmp_connless_data_request(struct lsap_cb *self, struct sk_buff *userdata,
struct sk_buff *clone_skb;
struct lap_cb *lap;
- IRDA_ASSERT(userdata != NULL, return -1;);
+ IRDA_ASSERT(userdata, return -1;);
/* Make room for MUX and PID header */
IRDA_ASSERT(skb_headroom(userdata) >= LMP_HEADER+LMP_PID_HEADER,
@@ -1202,10 +1200,7 @@ int irlmp_connless_data_request(struct lsap_cb *self, struct sk_buff *userdata,
/* Insert protocol identifier */
skb_push(userdata, LMP_PID_HEADER);
- if(self != NULL)
- userdata->data[0] = self->pid;
- else
- userdata->data[0] = pid;
+ userdata->data[0] = self ? self->pid : pid;
/* Connectionless sockets must use 0x70 */
skb_push(userdata, LMP_HEADER);
@@ -1213,7 +1208,7 @@ int irlmp_connless_data_request(struct lsap_cb *self, struct sk_buff *userdata,
/* Try to send Connectionless packets out on all links */
lap = (struct lap_cb *) hashbin_get_first(irlmp->links);
- while (lap != NULL) {
+ while (lap) {
IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, return -1;);
clone_skb = skb_clone(userdata, GFP_ATOMIC);
@@ -1243,9 +1238,9 @@ int irlmp_connless_data_request(struct lsap_cb *self, struct sk_buff *userdata,
#ifdef CONFIG_IRDA_ULTRA
void irlmp_connless_data_indication(struct lsap_cb *self, struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/* Hide LMP and PID header from layer above */
skb_pull(skb, LMP_HEADER+LMP_PID_HEADER);
@@ -1280,7 +1275,7 @@ void irlmp_status_indication(struct lap_cb *self,
/*
* Inform service user if he has requested it
*/
- if (curr->notify.status_indication != NULL)
+ if (curr->notify.status_indication)
curr->notify.status_indication(curr->notify.instance,
link, lock);
else
@@ -1323,20 +1318,20 @@ void irlmp_flow_indication(struct lap_cb *self, LOCAL_FLOW flow)
/* Try to find the next lsap we should poll. */
next = self->flow_next;
/* If we have no lsap, restart from first one */
- if(next == NULL)
+ if (!next)
next = (struct lsap_cb *) hashbin_get_first(self->lsaps);
/* Verify current one and find the next one */
curr = hashbin_find_next(self->lsaps, (long) next, NULL,
(void *) &self->flow_next);
/* Uh-oh... Paranoia */
- if(curr == NULL)
+ if (!curr)
break;
pr_debug("%s() : curr is %p, next was %p and is now %p, still %d to go - queue len = %d\n",
__func__, curr, next, self->flow_next, lsap_todo,
IRLAP_GET_TX_QUEUE_LEN(self->irlap));
/* Inform lsap user that it can send one more packet. */
- if (curr->notify.flow_indication != NULL)
+ if (curr->notify.flow_indication)
curr->notify.flow_indication(curr->notify.instance,
curr, flow);
else
@@ -1534,7 +1529,7 @@ void *irlmp_register_client(__u16 hint_mask, DISCOVERY_CALLBACK1 disco_clb,
{
irlmp_client_t *client;
- IRDA_ASSERT(irlmp != NULL, return NULL;);
+ IRDA_ASSERT(irlmp, return NULL;);
/* Make a new registration */
client = kmalloc(sizeof(*client), GFP_ATOMIC);
@@ -1631,7 +1626,7 @@ static int irlmp_slsap_inuse(__u8 slsap_sel)
struct lap_cb *lap;
unsigned long flags;
- IRDA_ASSERT(irlmp != NULL, return TRUE;);
+ IRDA_ASSERT(irlmp, return TRUE;);
IRDA_ASSERT(irlmp->magic == LMP_MAGIC, return TRUE;);
IRDA_ASSERT(slsap_sel != LSAP_ANY, return TRUE;);
@@ -1653,7 +1648,7 @@ static int irlmp_slsap_inuse(__u8 slsap_sel)
spin_lock_irqsave_nested(&irlmp->links->hb_spinlock, flags,
SINGLE_DEPTH_NESTING);
lap = (struct lap_cb *) hashbin_get_first(irlmp->links);
- while (lap != NULL) {
+ while (lap) {
IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, goto errlap;);
/* Careful for priority inversions here !
@@ -1663,7 +1658,7 @@ static int irlmp_slsap_inuse(__u8 slsap_sel)
/* For this IrLAP, check all the LSAPs */
self = (struct lsap_cb *) hashbin_get_first(lap->lsaps);
- while (self != NULL) {
+ while (self) {
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC,
goto errlsap;);
@@ -1690,7 +1685,7 @@ static int irlmp_slsap_inuse(__u8 slsap_sel)
spin_lock_irqsave(&irlmp->unconnected_lsaps->hb_spinlock, flags);
self = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
- while (self != NULL) {
+ while (self) {
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, goto erruncon;);
if ((self->slsap_sel == slsap_sel)) {
pr_debug("Source LSAP selector=%02x in use (unconnected)\n",
@@ -1730,7 +1725,7 @@ static __u8 irlmp_find_free_slsap(void)
__u8 lsap_sel;
int wrapped = 0;
- IRDA_ASSERT(irlmp != NULL, return -1;);
+ IRDA_ASSERT(irlmp, return -1;);
IRDA_ASSERT(irlmp->magic == LMP_MAGIC, return -1;);
/* Most users don't really care which LSAPs they are given,
@@ -1836,7 +1831,7 @@ static void *irlmp_seq_hb_idx(struct irlmp_iter_state *iter, loff_t *off)
spin_lock_irq(&iter->hashbin->hb_spinlock);
for (element = hashbin_get_first(iter->hashbin);
- element != NULL;
+ element;
element = hashbin_get_next(iter->hashbin)) {
if (!off || (*off)-- == 0) {
/* NB: hashbin left locked */
@@ -1889,8 +1884,7 @@ static void *irlmp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
}
v = hashbin_get_next(iter->hashbin);
-
- if (v == NULL) { /* no more in this hash bin */
+ if (!v) { /* no more in this hash bin */
spin_unlock_irq(&iter->hashbin->hb_spinlock);
if (iter->hashbin == irlmp->unconnected_lsaps)
@@ -1947,7 +1941,7 @@ static int irlmp_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, "\n Connected LSAPs:\n");
for (self = (struct lsap_cb *) hashbin_get_first(lap->lsaps);
- self != NULL;
+ self;
self = (struct lsap_cb *)hashbin_get_next(lap->lsaps)) {
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC,
goto outloop;);
@@ -1978,7 +1972,7 @@ static const struct seq_operations irlmp_seq_ops = {
static int irlmp_seq_open(struct inode *inode, struct file *file)
{
- IRDA_ASSERT(irlmp != NULL, return -EINVAL;);
+ IRDA_ASSERT(irlmp, return -EINVAL;);
return seq_open_private(file, &irlmp_seq_ops,
sizeof(struct irlmp_iter_state));
diff --git a/drivers/staging/irda/net/irlmp_event.c b/drivers/staging/irda/net/irlmp_event.c
index e306cf2c1e04..5856c8ed7dea 100644
--- a/drivers/staging/irda/net/irlmp_event.c
+++ b/drivers/staging/irda/net/irlmp_event.c
@@ -137,7 +137,7 @@ static inline void irlmp_next_lsap_state(struct lsap_cb *self,
int irlmp_do_lsap_event(struct lsap_cb *self, IRLMP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
pr_debug("%s(), EVENT = %s, STATE = %s\n",
@@ -155,7 +155,7 @@ int irlmp_do_lsap_event(struct lsap_cb *self, IRLMP_EVENT event,
void irlmp_do_lap_event(struct lap_cb *self, IRLMP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
pr_debug("%s(), EVENT = %s, STATE = %s\n", __func__,
@@ -180,7 +180,7 @@ void irlmp_watchdog_timer_expired(void *data)
{
struct lsap_cb *self = (struct lsap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
irlmp_do_lsap_event(self, LM_WATCHDOG_TIMEOUT, NULL);
@@ -190,7 +190,7 @@ void irlmp_idle_timer_expired(void *data)
{
struct lap_cb *self = (struct lap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
irlmp_do_lap_event(self, LM_LAP_IDLE_TIMEOUT, NULL);
@@ -248,7 +248,7 @@ irlmp_do_all_lsap_event(hashbin_t * lsap_hashbin,
static void irlmp_state_standby(struct lap_cb *self, IRLMP_EVENT event,
struct sk_buff *skb)
{
- IRDA_ASSERT(self->irlap != NULL, return;);
+ IRDA_ASSERT(self->irlap, return;);
switch (event) {
case LM_LAP_DISCOVERY_REQUEST:
@@ -479,7 +479,7 @@ static int irlmp_state_disconnected(struct lsap_cb *self, IRLMP_EVENT event,
{
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
switch (event) {
@@ -557,7 +557,7 @@ static int irlmp_state_connect(struct lsap_cb *self, IRLMP_EVENT event,
struct lsap_cb *lsap;
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
switch (event) {
@@ -570,8 +570,8 @@ static int irlmp_state_connect(struct lsap_cb *self, IRLMP_EVENT event,
NULL);
IRDA_ASSERT(lsap == self, return -1;);
- IRDA_ASSERT(self->lap != NULL, return -1;);
- IRDA_ASSERT(self->lap->lsaps != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
+ IRDA_ASSERT(self->lap->lsaps, return -1;);
hashbin_insert(self->lap->lsaps, (irda_queue_t *) self,
(long) self, NULL);
@@ -617,7 +617,7 @@ static int irlmp_state_connect_pend(struct lsap_cb *self, IRLMP_EVENT event,
struct sk_buff *tx_skb;
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
switch (event) {
@@ -681,9 +681,9 @@ static int irlmp_state_dtr(struct lsap_cb *self, IRLMP_EVENT event,
LM_REASON reason;
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
- IRDA_ASSERT(self->lap != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
switch (event) {
case LM_DATA_REQUEST: /* Optimize for the common case */
@@ -694,7 +694,7 @@ static int irlmp_state_dtr(struct lsap_cb *self, IRLMP_EVENT event,
irlmp_data_indication(self, skb);
break;
case LM_UDATA_REQUEST:
- IRDA_ASSERT(skb != NULL, return -1;);
+ IRDA_ASSERT(skb, return -1;);
irlmp_send_data_pdu(self->lap, self->dlsap_sel,
self->slsap_sel, TRUE, skb);
break;
@@ -737,10 +737,9 @@ static int irlmp_state_dtr(struct lsap_cb *self, IRLMP_EVENT event,
case LM_DISCONNECT_INDICATION:
irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
- IRDA_ASSERT(self->lap != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
IRDA_ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
-
- IRDA_ASSERT(skb != NULL, return -1;);
+ IRDA_ASSERT(skb, return -1;);
IRDA_ASSERT(skb->len > 3, return -1;);
reason = skb->data[3];
@@ -771,7 +770,7 @@ static int irlmp_state_setup(struct lsap_cb *self, IRLMP_EVENT event,
LM_REASON reason;
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
switch (event) {
@@ -785,10 +784,9 @@ static int irlmp_state_setup(struct lsap_cb *self, IRLMP_EVENT event,
case LM_DISCONNECT_INDICATION:
irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
- IRDA_ASSERT(self->lap != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
IRDA_ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
-
- IRDA_ASSERT(skb != NULL, return -1;);
+ IRDA_ASSERT(skb, return -1;);
IRDA_ASSERT(skb->len > 3, return -1;);
reason = skb->data[3];
@@ -803,7 +801,7 @@ static int irlmp_state_setup(struct lsap_cb *self, IRLMP_EVENT event,
del_timer(&self->watchdog_timer);
- IRDA_ASSERT(self->lap != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
IRDA_ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
reason = irlmp_convert_lap_reason(self->lap->reason);
@@ -813,7 +811,7 @@ static int irlmp_state_setup(struct lsap_cb *self, IRLMP_EVENT event,
case LM_WATCHDOG_TIMEOUT:
pr_debug("%s() WATCHDOG_TIMEOUT!\n", __func__);
- IRDA_ASSERT(self->lap != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
@@ -842,12 +840,12 @@ static int irlmp_state_setup_pend(struct lsap_cb *self, IRLMP_EVENT event,
LM_REASON reason;
int ret = 0;
- IRDA_ASSERT(self != NULL, return -1;);
- IRDA_ASSERT(irlmp != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
+ IRDA_ASSERT(irlmp, return -1;);
switch (event) {
case LM_LAP_CONNECT_CONFIRM:
- IRDA_ASSERT(self->conn_skb != NULL, return -1;);
+ IRDA_ASSERT(self->conn_skb, return -1;);
tx_skb = self->conn_skb;
self->conn_skb = NULL;
@@ -862,7 +860,7 @@ static int irlmp_state_setup_pend(struct lsap_cb *self, IRLMP_EVENT event,
case LM_WATCHDOG_TIMEOUT:
pr_debug("%s() : WATCHDOG_TIMEOUT !\n", __func__);
- IRDA_ASSERT(self->lap != NULL, return -1;);
+ IRDA_ASSERT(self->lap, return -1;);
irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
diff --git a/drivers/staging/irda/net/irlmp_frame.c b/drivers/staging/irda/net/irlmp_frame.c
index 38b0f994bc7b..abcbcc8c7a4c 100644
--- a/drivers/staging/irda/net/irlmp_frame.c
+++ b/drivers/staging/irda/net/irlmp_frame.c
@@ -60,9 +60,9 @@ void irlmp_send_lcf_pdu(struct lap_cb *self, __u8 dlsap, __u8 slsap,
{
__u8 *frame;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
frame = skb->data;
@@ -93,7 +93,7 @@ void irlmp_link_data_indication(struct lap_cb *self, struct sk_buff *skb,
__u8 dlsap_sel; /* Destination LSAP address */
__u8 *fp;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
IRDA_ASSERT(skb->len > 2, return;);
@@ -129,7 +129,7 @@ void irlmp_link_data_indication(struct lap_cb *self, struct sk_buff *skb,
lsap = irlmp_find_lsap(self, dlsap_sel, slsap_sel, 0,
self->lsaps);
- if (lsap == NULL) {
+ if (!lsap) {
pr_debug("IrLMP, Sorry, no LSAP for received frame!\n");
pr_debug("%s(), slsap_sel = %02x, dlsap_sel = %02x\n",
__func__, slsap_sel, dlsap_sel);
@@ -202,7 +202,7 @@ void irlmp_link_unitdata_indication(struct lap_cb *self, struct sk_buff *skb)
__u8 *fp;
unsigned long flags;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
IRDA_ASSERT(skb->len > 2, return;);
@@ -231,7 +231,7 @@ void irlmp_link_unitdata_indication(struct lap_cb *self, struct sk_buff *skb)
/* Search the connectionless LSAP */
spin_lock_irqsave(&irlmp->unconnected_lsaps->hb_spinlock, flags);
lsap = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
- while (lsap != NULL) {
+ while (lsap) {
/*
* Check if source LSAP and dest LSAP selectors and PID match.
*/
@@ -264,7 +264,7 @@ void irlmp_link_disconnect_indication(struct lap_cb *lap,
LAP_REASON reason,
struct sk_buff *skb)
{
- IRDA_ASSERT(lap != NULL, return;);
+ IRDA_ASSERT(lap, return;);
IRDA_ASSERT(lap->magic == LMP_LAP_MAGIC, return;);
lap->reason = reason;
@@ -307,9 +307,9 @@ void irlmp_link_connect_indication(struct lap_cb *self, __u32 saddr,
void irlmp_link_connect_confirm(struct lap_cb *self, struct qos_info *qos,
struct sk_buff *skb)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
- IRDA_ASSERT(qos != NULL, return;);
+ IRDA_ASSERT(qos, return;);
/* Don't need use the skb for now */
@@ -350,7 +350,7 @@ void irlmp_link_connect_confirm(struct lap_cb *self, struct qos_info *qos,
void irlmp_link_discovery_indication(struct lap_cb *self,
discovery_t *discovery)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
/* Add to main log, cleanup */
@@ -371,7 +371,7 @@ void irlmp_link_discovery_indication(struct lap_cb *self,
*/
void irlmp_link_discovery_confirm(struct lap_cb *self, hashbin_t *log)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
/* Add to main log, cleanup */
@@ -441,7 +441,7 @@ static struct lsap_cb *irlmp_find_lsap(struct lap_cb *self, __u8 dlsap_sel,
spin_lock_irqsave(&queue->hb_spinlock, flags);
lsap = (struct lsap_cb *) hashbin_get_first(queue);
- while (lsap != NULL) {
+ while (lsap) {
/*
* If this is an incoming connection, then the destination
* LSAP selector may have been specified as LM_ANY so that
diff --git a/drivers/staging/irda/net/irnetlink.c b/drivers/staging/irda/net/irnetlink.c
index 7fc340e574cf..300cf57317d9 100644
--- a/drivers/staging/irda/net/irnetlink.c
+++ b/drivers/staging/irda/net/irnetlink.c
@@ -96,7 +96,7 @@ static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
&irda_nl_family, 0, IRDA_NL_CMD_GET_MODE);
- if (hdr == NULL) {
+ if (!hdr) {
ret = -EMSGSIZE;
goto err_out;
}
diff --git a/drivers/staging/irda/net/irproc.c b/drivers/staging/irda/net/irproc.c
index 77cfdde9d82f..2ddac9f15e6c 100644
--- a/drivers/staging/irda/net/irproc.c
+++ b/drivers/staging/irda/net/irproc.c
@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
int i;
proc_irda = proc_mkdir("irda", init_net.proc_net);
- if (proc_irda == NULL)
+ if (!proc_irda)
return;
for (i = 0; i < ARRAY_SIZE(irda_dirs); i++)
diff --git a/drivers/staging/irda/net/irqueue.c b/drivers/staging/irda/net/irqueue.c
index 14291cbc4097..ee9d30536a9a 100644
--- a/drivers/staging/irda/net/irqueue.c
+++ b/drivers/staging/irda/net/irqueue.c
@@ -237,7 +237,7 @@ static void enqueue_first(irda_queue_t **queue, irda_queue_t* element)
/*
* Check if queue is empty.
*/
- if ( *queue == NULL ) {
+ if (!*queue) {
/*
* Queue is empty. Insert one element into the queue.
*/
@@ -273,7 +273,7 @@ static irda_queue_t *dequeue_first(irda_queue_t **queue)
*/
ret = *queue;
- if ( *queue == NULL ) {
+ if (!*queue) {
/*
* Queue was empty.
*/
@@ -314,7 +314,7 @@ static irda_queue_t *dequeue_general(irda_queue_t **queue, irda_queue_t* element
*/
ret = *queue;
- if ( *queue == NULL ) {
+ if (!*queue) {
/*
* Queue was empty.
*/
@@ -390,7 +390,7 @@ int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
unsigned long flags = 0;
int i;
- IRDA_ASSERT(hashbin != NULL, return -1;);
+ IRDA_ASSERT(hashbin, return -1;);
IRDA_ASSERT(hashbin->magic == HB_MAGIC, return -1;);
/* Synchronize */
@@ -449,7 +449,7 @@ void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv,
unsigned long flags = 0;
int bin;
- IRDA_ASSERT( hashbin != NULL, return;);
+ IRDA_ASSERT(hashbin, return;);
IRDA_ASSERT( hashbin->magic == HB_MAGIC, return;);
/*
@@ -505,7 +505,7 @@ void *hashbin_remove_first( hashbin_t *hashbin)
} /* Default is no-lock */
entry = hashbin_get_first( hashbin);
- if ( entry != NULL) {
+ if (entry) {
int bin;
long hashv;
/*
@@ -560,7 +560,7 @@ void* hashbin_remove( hashbin_t* hashbin, long hashv, const char* name)
unsigned long flags = 0;
irda_queue_t* entry;
- IRDA_ASSERT( hashbin != NULL, return NULL;);
+ IRDA_ASSERT(hashbin, return NULL;);
IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
/*
@@ -651,9 +651,9 @@ void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry)
int bin;
long hashv;
- IRDA_ASSERT( hashbin != NULL, return NULL;);
+ IRDA_ASSERT(hashbin, return NULL;);
IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
- IRDA_ASSERT( entry != NULL, return NULL;);
+ IRDA_ASSERT(entry, return NULL;);
/* Synchronize */
if ( hashbin->hb_type & HB_LOCK ) {
@@ -661,7 +661,7 @@ void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry)
} /* Default is no-lock */
/* Check if valid and not already removed... */
- if((entry->q_next == NULL) || (entry->q_prev == NULL)) {
+ if (!entry->q_next || !entry->q_prev) {
entry = NULL;
goto out;
}
@@ -712,7 +712,7 @@ void* hashbin_find( hashbin_t* hashbin, long hashv, const char* name )
pr_debug("hashbin_find()\n");
- IRDA_ASSERT( hashbin != NULL, return NULL;);
+ IRDA_ASSERT(hashbin, return NULL;);
IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
/*
@@ -833,10 +833,10 @@ irda_queue_t *hashbin_get_first( hashbin_t* hashbin)
irda_queue_t *entry;
int i;
- IRDA_ASSERT( hashbin != NULL, return NULL;);
+ IRDA_ASSERT(hashbin, return NULL;);
IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
- if ( hashbin == NULL)
+ if (!hashbin)
return NULL;
for ( i = 0; i < HASHBIN_SIZE; i ++ ) {
@@ -869,11 +869,11 @@ irda_queue_t *hashbin_get_next( hashbin_t *hashbin)
int bin;
int i;
- IRDA_ASSERT( hashbin != NULL, return NULL;);
+ IRDA_ASSERT(hashbin, return NULL;);
IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
- if ( hashbin->hb_current == NULL) {
- IRDA_ASSERT( hashbin->hb_current != NULL, return NULL;);
+ if (!hashbin->hb_current) {
+ IRDA_ASSERT(hashbin->hb_current, return NULL;);
return NULL;
}
entry = hashbin->hb_current->q_next;
diff --git a/drivers/staging/irda/net/irsysctl.c b/drivers/staging/irda/net/irsysctl.c
index 873da5e7d428..70b8d39b5c1c 100644
--- a/drivers/staging/irda/net/irsysctl.c
+++ b/drivers/staging/irda/net/irsysctl.c
@@ -99,8 +99,8 @@ static int do_discovery(struct ctl_table *table, int write,
if (ret)
return ret;
- if (irlmp == NULL)
- return -ENODEV;
+ if (!irlmp)
+ return -ENODEV;
if (sysctl_discovery)
irlmp_start_discovery_timer(irlmp, sysctl_discovery_timeout*HZ);
diff --git a/drivers/staging/irda/net/irttp.c b/drivers/staging/irda/net/irttp.c
index bcab5a60cd47..2adba87aeb68 100644
--- a/drivers/staging/irda/net/irttp.c
+++ b/drivers/staging/irda/net/irttp.c
@@ -91,7 +91,7 @@ static pi_param_info_t param_info = { pi_major_call_table, 1, 0x0f, 4 };
int __init irttp_init(void)
{
irttp = kzalloc(sizeof(struct irttp_cb), GFP_KERNEL);
- if (irttp == NULL)
+ if (!irttp)
return -ENOMEM;
irttp->magic = TTP_MAGIC;
@@ -209,7 +209,7 @@ static void irttp_flush_queues(struct tsap_cb *self)
{
struct sk_buff *skb;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
/* Deallocate frames waiting to be sent */
@@ -237,7 +237,7 @@ static struct sk_buff *irttp_reassemble_skb(struct tsap_cb *self)
struct sk_buff *skb, *frag;
int n = 0; /* Fragment index */
- IRDA_ASSERT(self != NULL, return NULL;);
+ IRDA_ASSERT(self, return NULL;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return NULL;);
pr_debug("%s(), self->rx_sdu_size=%d\n", __func__,
@@ -294,9 +294,9 @@ static inline void irttp_fragment_skb(struct tsap_cb *self,
struct sk_buff *frag;
__u8 *frame;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
/*
* Split frame into a number of segments
@@ -350,7 +350,7 @@ static int irttp_param_max_sdu_size(void *instance, irda_param_t *param,
self = instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
if (get)
@@ -404,7 +404,7 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
}
self = kzalloc(sizeof(*self), GFP_ATOMIC);
- if (self == NULL)
+ if (!self)
return NULL;
/* Initialize internal objects */
@@ -422,7 +422,7 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
ttp_notify.data_indication = irttp_data_indication;
ttp_notify.udata_indication = irttp_udata_indication;
ttp_notify.flow_indication = irttp_flow_indication;
- if (notify->status_indication != NULL)
+ if (notify->status_indication)
ttp_notify.status_indication = irttp_status_indication;
ttp_notify.instance = self;
strncpy(ttp_notify.name, notify->name, NOTIFY_MAX_NAME);
@@ -434,7 +434,7 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
* Create LSAP at IrLMP layer
*/
lsap = irlmp_open_lsap(stsap_sel, &ttp_notify, 0);
- if (lsap == NULL) {
+ if (!lsap) {
pr_debug("%s: unable to allocate LSAP!!\n", __func__);
__irttp_close_tsap(self);
return NULL;
@@ -472,7 +472,7 @@ EXPORT_SYMBOL(irttp_open_tsap);
static void __irttp_close_tsap(struct tsap_cb *self)
{
/* First make sure we're connected. */
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
irttp_flush_queues(self);
@@ -504,7 +504,7 @@ int irttp_close_tsap(struct tsap_cb *self)
{
struct tsap_cb *tsap;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
/* Make sure tsap has been disconnected */
@@ -547,9 +547,9 @@ int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb)
{
int ret;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
- IRDA_ASSERT(skb != NULL, return -1;);
+ IRDA_ASSERT(skb, return -1;);
/* Take shortcut on zero byte packets */
if (skb->len == 0) {
@@ -594,9 +594,9 @@ int irttp_data_request(struct tsap_cb *self, struct sk_buff *skb)
__u8 *frame;
int ret;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
- IRDA_ASSERT(skb != NULL, return -1;);
+ IRDA_ASSERT(skb, return -1;);
pr_debug("%s() : queue len = %d\n", __func__,
skb_queue_len(&self->tx_queue));
@@ -769,7 +769,7 @@ static void irttp_run_tx_queue(struct tsap_cb *self)
* remains in IrLAP (retry on the link or else) after we
* close the socket, we are dead !
* Jean II */
- if (skb->sk != NULL) {
+ if (skb->sk) {
/* IrSOCK application, IrOBEX, ... */
skb_orphan(skb);
}
@@ -815,7 +815,7 @@ static inline void irttp_give_credit(struct tsap_cb *self)
unsigned long flags;
int n;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
pr_debug("%s() send=%d,avail=%d,remote=%d\n",
@@ -870,9 +870,9 @@ static int irttp_udata_indication(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
- IRDA_ASSERT(skb != NULL, return -1;);
+ IRDA_ASSERT(skb, return -1;);
self->stats.rx_packets++;
@@ -985,7 +985,7 @@ static void irttp_status_indication(void *instance,
self = instance;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
/* Check if client has already closed the TSAP and gone away */
@@ -995,7 +995,7 @@ static void irttp_status_indication(void *instance,
/*
* Inform service user if he has requested it
*/
- if (self->notify.status_indication != NULL)
+ if (self->notify.status_indication)
self->notify.status_indication(self->notify.instance,
link, lock);
else
@@ -1014,7 +1014,7 @@ static void irttp_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
self = instance;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
pr_debug("%s(instance=%p)\n", __func__, self);
@@ -1055,7 +1055,7 @@ static void irttp_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
*/
void irttp_flow_request(struct tsap_cb *self, LOCAL_FLOW flow)
{
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
switch (flow) {
@@ -1095,7 +1095,7 @@ int irttp_connect_request(struct tsap_cb *self, __u8 dtsap_sel,
pr_debug("%s(), max_sdu_size=%d\n", __func__, max_sdu_size);
- IRDA_ASSERT(self != NULL, return -EBADR;);
+ IRDA_ASSERT(self, return -EBADR;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -EBADR;);
if (self->connected) {
@@ -1105,7 +1105,7 @@ int irttp_connect_request(struct tsap_cb *self, __u8 dtsap_sel,
}
/* Any userdata supplied? */
- if (userdata == NULL) {
+ if (!userdata) {
tx_skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER,
GFP_ATOMIC);
if (!tx_skb)
@@ -1193,9 +1193,9 @@ static void irttp_connect_confirm(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
self->max_seg_size = max_seg_size - TTP_HEADER;
self->max_header_size = max_header_size + TTP_HEADER;
@@ -1277,9 +1277,9 @@ static void irttp_connect_indication(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
- IRDA_ASSERT(skb != NULL, return;);
+ IRDA_ASSERT(skb, return;);
lsap = sap;
@@ -1345,14 +1345,14 @@ int irttp_connect_response(struct tsap_cb *self, __u32 max_sdu_size,
int ret;
__u8 n;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
pr_debug("%s(), Source TSAP selector=%02x\n", __func__,
self->stsap_sel);
/* Any userdata supplied? */
- if (userdata == NULL) {
+ if (!userdata) {
tx_skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER,
GFP_ATOMIC);
if (!tx_skb)
@@ -1484,7 +1484,7 @@ int irttp_disconnect_request(struct tsap_cb *self, struct sk_buff *userdata,
{
int ret;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
/* Already disconnected? */
@@ -1580,7 +1580,7 @@ static void irttp_disconnect_indication(void *instance, void *sap,
self = instance;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return;);
/* Prevent higher layer to send more data */
@@ -1800,7 +1800,7 @@ static void *irttp_seq_start(struct seq_file *seq, loff_t *pos)
iter->id = 0;
for (self = (struct tsap_cb *) hashbin_get_first(irttp->tsaps);
- self != NULL;
+ self;
self = (struct tsap_cb *) hashbin_get_next(irttp->tsaps)) {
if (iter->id == *pos)
break;
diff --git a/drivers/staging/irda/net/parameters.c b/drivers/staging/irda/net/parameters.c
index 16ce32ffe004..2d891729815d 100644
--- a/drivers/staging/irda/net/parameters.c
+++ b/drivers/staging/irda/net/parameters.c
@@ -456,8 +456,8 @@ int irda_param_insert(void *self, __u8 pi, __u8 *buf, int len,
int ret = -1;
int n = 0;
- IRDA_ASSERT(buf != NULL, return ret;);
- IRDA_ASSERT(info != NULL, return ret;);
+ IRDA_ASSERT(buf, return ret;);
+ IRDA_ASSERT(info, return ret;);
pi_minor = pi & info->pi_mask;
pi_major = pi >> info->pi_major_offset;
@@ -511,8 +511,8 @@ static int irda_param_extract(void *self, __u8 *buf, int len,
int ret = -1;
int n = 0;
- IRDA_ASSERT(buf != NULL, return ret;);
- IRDA_ASSERT(info != NULL, return ret;);
+ IRDA_ASSERT(buf, return ret;);
+ IRDA_ASSERT(info, return ret;);
pi_minor = buf[n] & info->pi_mask;
pi_major = buf[n] >> info->pi_major_offset;
@@ -564,8 +564,8 @@ int irda_param_extract_all(void *self, __u8 *buf, int len,
int ret = -1;
int n = 0;
- IRDA_ASSERT(buf != NULL, return ret;);
- IRDA_ASSERT(info != NULL, return ret;);
+ IRDA_ASSERT(buf, return ret;);
+ IRDA_ASSERT(info, return ret;);
/*
* Parse all parameters. Each parameter must be at least two bytes
diff --git a/drivers/staging/irda/net/qos.c b/drivers/staging/irda/net/qos.c
index 25ba8509ad3e..b3816b90ff2c 100644
--- a/drivers/staging/irda/net/qos.c
+++ b/drivers/staging/irda/net/qos.c
@@ -278,8 +278,8 @@ static inline int value_highest_bit(__u32 value, __u32 *array, int size, __u16 *
*/
void irda_qos_compute_intersection(struct qos_info *qos, struct qos_info *new)
{
- IRDA_ASSERT(qos != NULL, return;);
- IRDA_ASSERT(new != NULL, return;);
+ IRDA_ASSERT(qos, return;);
+ IRDA_ASSERT(new, return;);
/* Apply */
qos->baud_rate.bits &= new->baud_rate.bits;
@@ -529,7 +529,7 @@ static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get)
struct irlap_cb *self = (struct irlap_cb *) instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
if (get) {
@@ -565,7 +565,7 @@ static int irlap_param_link_disconnect(void *instance, irda_param_t *param,
struct irlap_cb *self = (struct irlap_cb *) instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
if (get)
@@ -597,7 +597,7 @@ static int irlap_param_max_turn_time(void *instance, irda_param_t *param,
{
struct irlap_cb *self = (struct irlap_cb *) instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
if (get)
@@ -619,7 +619,7 @@ static int irlap_param_data_size(void *instance, irda_param_t *param, int get)
{
struct irlap_cb *self = (struct irlap_cb *) instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
if (get)
@@ -642,7 +642,7 @@ static int irlap_param_window_size(void *instance, irda_param_t *param,
{
struct irlap_cb *self = (struct irlap_cb *) instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
if (get)
@@ -663,7 +663,7 @@ static int irlap_param_additional_bofs(void *instance, irda_param_t *param, int
{
struct irlap_cb *self = (struct irlap_cb *) instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
if (get)
@@ -685,7 +685,7 @@ static int irlap_param_min_turn_time(void *instance, irda_param_t *param,
{
struct irlap_cb *self = (struct irlap_cb *) instance;
- IRDA_ASSERT(self != NULL, return -1;);
+ IRDA_ASSERT(self, return -1;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
if (get)
@@ -745,7 +745,7 @@ void irda_qos_bits_to_value(struct qos_info *qos)
{
int index;
- IRDA_ASSERT(qos != NULL, return;);
+ IRDA_ASSERT(qos, return;);
index = msb_index(qos->baud_rate.bits);
qos->baud_rate.value = baud_rates[index];
diff --git a/drivers/staging/irda/net/timer.c b/drivers/staging/irda/net/timer.c
index f2280f73b057..3d47ac9df2fe 100644
--- a/drivers/staging/irda/net/timer.c
+++ b/drivers/staging/irda/net/timer.c
@@ -142,7 +142,7 @@ static void irlap_slot_timer_expired(void *data)
{
struct irlap_cb *self = (struct irlap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlap_do_event(self, SLOT_TIMER_EXPIRED, NULL, NULL);
@@ -158,7 +158,7 @@ static void irlap_query_timer_expired(void *data)
{
struct irlap_cb *self = (struct irlap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlap_do_event(self, QUERY_TIMER_EXPIRED, NULL, NULL);
@@ -174,7 +174,7 @@ static void irlap_final_timer_expired(void *data)
{
struct irlap_cb *self = (struct irlap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlap_do_event(self, FINAL_TIMER_EXPIRED, NULL, NULL);
@@ -190,7 +190,7 @@ static void irlap_wd_timer_expired(void *data)
{
struct irlap_cb *self = (struct irlap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlap_do_event(self, WD_TIMER_EXPIRED, NULL, NULL);
@@ -206,7 +206,7 @@ static void irlap_backoff_timer_expired(void *data)
{
struct irlap_cb *self = (struct irlap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
irlap_do_event(self, BACKOFF_TIMER_EXPIRED, NULL, NULL);
@@ -222,7 +222,7 @@ static void irlap_media_busy_expired(void *data)
{
struct irlap_cb *self = (struct irlap_cb *) data;
- IRDA_ASSERT(self != NULL, return;);
+ IRDA_ASSERT(self, return;);
irda_device_set_media_busy(self->netdev, FALSE);
/* Note : the LAP event will be send in irlap_stop_mbusy_timer(),
diff --git a/drivers/staging/irda/net/wrapper.c b/drivers/staging/irda/net/wrapper.c
index 40a0f993bf13..526f86d27268 100644
--- a/drivers/staging/irda/net/wrapper.c
+++ b/drivers/staging/irda/net/wrapper.c
@@ -219,8 +219,7 @@ async_bump(struct net_device *dev,
* skb. But, if the frame is small, it is more efficient to
* copy it to save memory (copy will be fast anyway - that's
* called Rx-copy-break). Jean II */
- docopy = ((rx_buff->skb == NULL) ||
- (rx_buff->len < IRDA_RX_COPY_THRESHOLD));
+ docopy = !rx_buff->skb || rx_buff->len < IRDA_RX_COPY_THRESHOLD;
/* Allocate a new skb */
newskb = dev_alloc_skb(docopy ? rx_buff->len + 1 : rx_buff->truesize);
--
2.14.2
^ permalink raw reply related
* [PATCH 02/10] staging: irda: Delete ten error messages for a failed memory allocation
From: SF Markus Elfring @ 2017-10-12 10:40 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 10 Oct 2017 21:10:43 +0200
Omit extra messages for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/irias_object.c | 24 ++++--------------------
drivers/staging/irda/net/irlap_frame.c | 4 +---
drivers/staging/irda/net/irlmp.c | 1 -
drivers/staging/irda/net/irttp.c | 1 -
4 files changed, 5 insertions(+), 25 deletions(-)
diff --git a/drivers/staging/irda/net/irias_object.c b/drivers/staging/irda/net/irias_object.c
index 1064fac2fd36..4db986b9d756 100644
--- a/drivers/staging/irda/net/irias_object.c
+++ b/drivers/staging/irda/net/irias_object.c
@@ -49,17 +49,12 @@ struct ias_object *irias_new_object( char *name, int id)
struct ias_object *obj;
obj = kzalloc(sizeof(*obj), GFP_ATOMIC);
- if (obj == NULL) {
- net_warn_ratelimited("%s(), Unable to allocate object!\n",
- __func__);
+ if (!obj)
return NULL;
- }
obj->magic = IAS_OBJECT_MAGIC;
obj->name = kstrndup(name, IAS_MAX_CLASSNAME, GFP_ATOMIC);
if (!obj->name) {
- net_warn_ratelimited("%s(), Unable to allocate name!\n",
- __func__);
kfree(obj);
return NULL;
}
@@ -319,11 +314,8 @@ void irias_add_integer_attrib(struct ias_object *obj, char *name, int value,
IRDA_ASSERT(name != NULL, return;);
attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
- if (attrib == NULL) {
- net_warn_ratelimited("%s: Unable to allocate attribute!\n",
- __func__);
+ if (!attrib)
return;
- }
attrib->magic = IAS_ATTRIB_MAGIC;
attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
@@ -363,11 +355,8 @@ void irias_add_octseq_attrib(struct ias_object *obj, char *name, __u8 *octets,
IRDA_ASSERT(octets != NULL, return;);
attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
- if (attrib == NULL) {
- net_warn_ratelimited("%s: Unable to allocate attribute!\n",
- __func__);
+ if (!attrib)
return;
- }
attrib->magic = IAS_ATTRIB_MAGIC;
attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
@@ -405,11 +394,8 @@ void irias_add_string_attrib(struct ias_object *obj, char *name, char *value,
IRDA_ASSERT(value != NULL, return;);
attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
- if (attrib == NULL) {
- net_warn_ratelimited("%s: Unable to allocate attribute!\n",
- __func__);
+ if (!attrib)
return;
- }
attrib->magic = IAS_ATTRIB_MAGIC;
attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
@@ -470,7 +456,6 @@ struct ias_value *irias_new_string_value(char *string)
value->charset = CS_ASCII;
value->t.string = kstrndup(string, IAS_MAX_STRING, GFP_ATOMIC);
if (!value->t.string) {
- net_warn_ratelimited("%s: Unable to kmalloc!\n", __func__);
kfree(value);
return NULL;
}
@@ -503,7 +488,6 @@ struct ias_value *irias_new_octseq_value(__u8 *octseq , int len)
value->t.oct_seq = kmemdup(octseq, len, GFP_ATOMIC);
if (value->t.oct_seq == NULL){
- net_warn_ratelimited("%s: Unable to kmalloc!\n", __func__);
kfree(value);
return NULL;
}
diff --git a/drivers/staging/irda/net/irlap_frame.c b/drivers/staging/irda/net/irlap_frame.c
index 21891ef7ee33..d4d88a5d2976 100644
--- a/drivers/staging/irda/net/irlap_frame.c
+++ b/drivers/staging/irda/net/irlap_frame.c
@@ -433,10 +433,8 @@ static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
}
discovery = kzalloc(sizeof(*discovery), GFP_ATOMIC);
- if (!discovery) {
- net_warn_ratelimited("%s: kmalloc failed!\n", __func__);
+ if (!discovery)
return;
- }
discovery->data.daddr = info->daddr;
discovery->data.saddr = self->saddr;
diff --git a/drivers/staging/irda/net/irlmp.c b/drivers/staging/irda/net/irlmp.c
index 38772a3b9df8..f075735e4b9b 100644
--- a/drivers/staging/irda/net/irlmp.c
+++ b/drivers/staging/irda/net/irlmp.c
@@ -641,7 +641,6 @@ struct lsap_cb *irlmp_dup(struct lsap_cb *orig, void *instance)
/* Allocate a new instance */
new = kmemdup(orig, sizeof(*new), GFP_ATOMIC);
if (!new) {
- pr_debug("%s(), unable to kmalloc\n", __func__);
spin_unlock_irqrestore(&irlmp->unconnected_lsaps->hb_spinlock,
flags);
return NULL;
diff --git a/drivers/staging/irda/net/irttp.c b/drivers/staging/irda/net/irttp.c
index 958bfbe38bfb..bcab5a60cd47 100644
--- a/drivers/staging/irda/net/irttp.c
+++ b/drivers/staging/irda/net/irttp.c
@@ -1443,7 +1443,6 @@ struct tsap_cb *irttp_dup(struct tsap_cb *orig, void *instance)
/* Allocate a new instance */
new = kmemdup(orig, sizeof(*new), GFP_ATOMIC);
if (!new) {
- pr_debug("%s(), unable to kmalloc\n", __func__);
spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
return NULL;
}
--
2.14.2
^ permalink raw reply related
* [PATCH 01/10] staging: irda: Improve a size determination in 20 functions
From: SF Markus Elfring @ 2017-10-12 10:39 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
In-Reply-To: <8152401b-d68d-c4fe-2619-82a09e0c52ec@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 10 Oct 2017 19:35:56 +0200
* Replace the specification of data types by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
* The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code place.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/irda/net/ircomm/ircomm_core.c | 2 +-
drivers/staging/irda/net/ircomm/ircomm_tty.c | 2 +-
drivers/staging/irda/net/irias_object.c | 16 ++++++++--------
drivers/staging/irda/net/irlap.c | 2 +-
drivers/staging/irda/net/irlap_frame.c | 7 ++++---
drivers/staging/irda/net/irlmp.c | 8 ++++----
drivers/staging/irda/net/irttp.c | 4 ++--
7 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/drivers/staging/irda/net/ircomm/ircomm_core.c b/drivers/staging/irda/net/ircomm/ircomm_core.c
index 3af219545f6d..6c02fbf380bd 100644
--- a/drivers/staging/irda/net/ircomm/ircomm_core.c
+++ b/drivers/staging/irda/net/ircomm/ircomm_core.c
@@ -114,7 +114,7 @@ struct ircomm_cb *ircomm_open(notify_t *notify, __u8 service_type, int line)
IRDA_ASSERT(ircomm != NULL, return NULL;);
- self = kzalloc(sizeof(struct ircomm_cb), GFP_KERNEL);
+ self = kzalloc(sizeof(*self), GFP_KERNEL);
if (self == NULL)
return NULL;
diff --git a/drivers/staging/irda/net/ircomm/ircomm_tty.c b/drivers/staging/irda/net/ircomm/ircomm_tty.c
index ec157c3419b5..d1beec413fa3 100644
--- a/drivers/staging/irda/net/ircomm/ircomm_tty.c
+++ b/drivers/staging/irda/net/ircomm/ircomm_tty.c
@@ -380,7 +380,7 @@ static int ircomm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
self = hashbin_lock_find(ircomm_tty, line, NULL);
if (!self) {
/* No, so make new instance */
- self = kzalloc(sizeof(struct ircomm_tty_cb), GFP_KERNEL);
+ self = kzalloc(sizeof(*self), GFP_KERNEL);
if (self == NULL)
return -ENOMEM;
diff --git a/drivers/staging/irda/net/irias_object.c b/drivers/staging/irda/net/irias_object.c
index 53b86d0e1630..1064fac2fd36 100644
--- a/drivers/staging/irda/net/irias_object.c
+++ b/drivers/staging/irda/net/irias_object.c
@@ -48,7 +48,7 @@ struct ias_object *irias_new_object( char *name, int id)
{
struct ias_object *obj;
- obj = kzalloc(sizeof(struct ias_object), GFP_ATOMIC);
+ obj = kzalloc(sizeof(*obj), GFP_ATOMIC);
if (obj == NULL) {
net_warn_ratelimited("%s(), Unable to allocate object!\n",
__func__);
@@ -318,7 +318,7 @@ void irias_add_integer_attrib(struct ias_object *obj, char *name, int value,
IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
IRDA_ASSERT(name != NULL, return;);
- attrib = kzalloc(sizeof(struct ias_attrib), GFP_ATOMIC);
+ attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
if (attrib == NULL) {
net_warn_ratelimited("%s: Unable to allocate attribute!\n",
__func__);
@@ -362,7 +362,7 @@ void irias_add_octseq_attrib(struct ias_object *obj, char *name, __u8 *octets,
IRDA_ASSERT(name != NULL, return;);
IRDA_ASSERT(octets != NULL, return;);
- attrib = kzalloc(sizeof(struct ias_attrib), GFP_ATOMIC);
+ attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
if (attrib == NULL) {
net_warn_ratelimited("%s: Unable to allocate attribute!\n",
__func__);
@@ -404,7 +404,7 @@ void irias_add_string_attrib(struct ias_object *obj, char *name, char *value,
IRDA_ASSERT(name != NULL, return;);
IRDA_ASSERT(value != NULL, return;);
- attrib = kzalloc(sizeof( struct ias_attrib), GFP_ATOMIC);
+ attrib = kzalloc(sizeof(*attrib), GFP_ATOMIC);
if (attrib == NULL) {
net_warn_ratelimited("%s: Unable to allocate attribute!\n",
__func__);
@@ -439,7 +439,7 @@ struct ias_value *irias_new_integer_value(int integer)
{
struct ias_value *value;
- value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC);
+ value = kzalloc(sizeof(*value), GFP_ATOMIC);
if (value == NULL)
return NULL;
@@ -462,7 +462,7 @@ struct ias_value *irias_new_string_value(char *string)
{
struct ias_value *value;
- value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC);
+ value = kzalloc(sizeof(*value), GFP_ATOMIC);
if (value == NULL)
return NULL;
@@ -491,7 +491,7 @@ struct ias_value *irias_new_octseq_value(__u8 *octseq , int len)
{
struct ias_value *value;
- value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC);
+ value = kzalloc(sizeof(*value), GFP_ATOMIC);
if (value == NULL)
return NULL;
@@ -514,7 +514,7 @@ struct ias_value *irias_new_missing_value(void)
{
struct ias_value *value;
- value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC);
+ value = kzalloc(sizeof(*value), GFP_ATOMIC);
if (value == NULL)
return NULL;
diff --git a/drivers/staging/irda/net/irlap.c b/drivers/staging/irda/net/irlap.c
index 1cde711bcab5..5dea721f44ac 100644
--- a/drivers/staging/irda/net/irlap.c
+++ b/drivers/staging/irda/net/irlap.c
@@ -110,7 +110,7 @@ struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
struct irlap_cb *self;
/* Initialize the irlap structure. */
- self = kzalloc(sizeof(struct irlap_cb), GFP_KERNEL);
+ self = kzalloc(sizeof(*self), GFP_KERNEL);
if (self == NULL)
return NULL;
diff --git a/drivers/staging/irda/net/irlap_frame.c b/drivers/staging/irda/net/irlap_frame.c
index debda3de4726..21891ef7ee33 100644
--- a/drivers/staging/irda/net/irlap_frame.c
+++ b/drivers/staging/irda/net/irlap_frame.c
@@ -432,7 +432,8 @@ static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
return;
}
- if ((discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC)) == NULL) {
+ discovery = kzalloc(sizeof(*discovery), GFP_ATOMIC);
+ if (!discovery) {
net_warn_ratelimited("%s: kmalloc failed!\n", __func__);
return;
}
@@ -539,7 +540,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
/*
* We now have some discovery info to deliver!
*/
- discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC);
+ discovery = kzalloc(sizeof(*discovery), GFP_ATOMIC);
if (!discovery)
return;
@@ -1201,7 +1202,7 @@ void irlap_send_test_frame(struct irlap_cb *self, __u8 caddr, __u32 daddr,
/* Broadcast frames must include saddr and daddr fields */
if (caddr == CBROADCAST) {
- frame = skb_put(tx_skb, sizeof(struct test_frame));
+ frame = skb_put(tx_skb, sizeof(*frame));
/* Insert the swapped addresses */
frame->saddr = cpu_to_le32(self->saddr);
diff --git a/drivers/staging/irda/net/irlmp.c b/drivers/staging/irda/net/irlmp.c
index 43964594aa12..38772a3b9df8 100644
--- a/drivers/staging/irda/net/irlmp.c
+++ b/drivers/staging/irda/net/irlmp.c
@@ -168,7 +168,7 @@ struct lsap_cb *irlmp_open_lsap(__u8 slsap_sel, notify_t *notify, __u8 pid)
return NULL;
/* Allocate new instance of a LSAP connection */
- self = kzalloc(sizeof(struct lsap_cb), GFP_ATOMIC);
+ self = kzalloc(sizeof(*self), GFP_ATOMIC);
if (self == NULL)
return NULL;
@@ -290,7 +290,7 @@ void irlmp_register_link(struct irlap_cb *irlap, __u32 saddr, notify_t *notify)
/*
* Allocate new instance of a LSAP connection
*/
- lap = kzalloc(sizeof(struct lap_cb), GFP_KERNEL);
+ lap = kzalloc(sizeof(*lap), GFP_KERNEL);
if (lap == NULL)
return;
@@ -1466,7 +1466,7 @@ void *irlmp_register_service(__u16 hints)
pr_debug("%s(), hints = %04x\n", __func__, hints);
/* Make a new registration */
- service = kmalloc(sizeof(irlmp_service_t), GFP_ATOMIC);
+ service = kmalloc(sizeof(*service), GFP_ATOMIC);
if (!service)
return NULL;
@@ -1538,7 +1538,7 @@ void *irlmp_register_client(__u16 hint_mask, DISCOVERY_CALLBACK1 disco_clb,
IRDA_ASSERT(irlmp != NULL, return NULL;);
/* Make a new registration */
- client = kmalloc(sizeof(irlmp_client_t), GFP_ATOMIC);
+ client = kmalloc(sizeof(*client), GFP_ATOMIC);
if (!client)
return NULL;
diff --git a/drivers/staging/irda/net/irttp.c b/drivers/staging/irda/net/irttp.c
index b6ab41d5b3a3..958bfbe38bfb 100644
--- a/drivers/staging/irda/net/irttp.c
+++ b/drivers/staging/irda/net/irttp.c
@@ -403,7 +403,7 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
return NULL;
}
- self = kzalloc(sizeof(struct tsap_cb), GFP_ATOMIC);
+ self = kzalloc(sizeof(*self), GFP_ATOMIC);
if (self == NULL)
return NULL;
@@ -1441,7 +1441,7 @@ struct tsap_cb *irttp_dup(struct tsap_cb *orig, void *instance)
}
/* Allocate a new instance */
- new = kmemdup(orig, sizeof(struct tsap_cb), GFP_ATOMIC);
+ new = kmemdup(orig, sizeof(*new), GFP_ATOMIC);
if (!new) {
pr_debug("%s(), unable to kmalloc\n", __func__);
spin_unlock_irqrestore(&irttp->tsaps->hb_spinlock, flags);
--
2.14.2
^ permalink raw reply related
* [PATCH 00/10] staging/irda/net: Adjustments for several function implementations
From: SF Markus Elfring @ 2017-10-12 10:38 UTC (permalink / raw)
To: devel, netdev, Al Viro, Corentin Labbe, David Howells,
David S. Miller, Georgiana Chelu, Greg Kroah-Hartman,
Johannes Berg, Julia Lawall, Samuel Ortiz, Srishti Sharma,
Stephen Hemminger, Yuan Linyu
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 12 Oct 2017 11:25:43 +0200
Several update suggestions were taken into account
from static source code analysis.
Markus Elfring (10):
Improve a size determination in 20 functions
Delete ten error messages for a failed memory allocation
Adjust 385 checks for null pointers
Delete an unnecessary variable initialisation in irlap_recv_discovery_xid_cmd()
Delete an unnecessary variable initialisation in irlap_recv_discovery_xid_rsp()
Delete an unnecessary variable initialisation in two functions
Delete an unnecessary variable initialisation in four functions
Use common error handling code in irias_new_object()
Combine some seq_printf() calls in two functions
Use seq_puts() in four functions
drivers/staging/irda/net/af_irda.c | 56 +++++----
drivers/staging/irda/net/discovery.c | 31 +++--
drivers/staging/irda/net/ircomm/ircomm_core.c | 10 +-
drivers/staging/irda/net/ircomm/ircomm_tty.c | 4 +-
drivers/staging/irda/net/irda_device.c | 2 +-
drivers/staging/irda/net/iriap.c | 61 +++++-----
drivers/staging/irda/net/iriap_event.c | 34 +++---
drivers/staging/irda/net/irias_object.c | 116 ++++++++-----------
drivers/staging/irda/net/irlan/irlan_common.c | 3 +-
drivers/staging/irda/net/irlap.c | 84 +++++++-------
drivers/staging/irda/net/irlap_event.c | 77 ++++++------
drivers/staging/irda/net/irlap_frame.c | 74 ++++++------
drivers/staging/irda/net/irlmp.c | 161 ++++++++++++--------------
drivers/staging/irda/net/irlmp_event.c | 50 ++++----
drivers/staging/irda/net/irlmp_frame.c | 24 ++--
drivers/staging/irda/net/irnetlink.c | 2 +-
drivers/staging/irda/net/irproc.c | 2 +-
drivers/staging/irda/net/irqueue.c | 32 ++---
drivers/staging/irda/net/irsysctl.c | 4 +-
drivers/staging/irda/net/irttp.c | 75 ++++++------
drivers/staging/irda/net/parameters.c | 12 +-
drivers/staging/irda/net/qos.c | 20 ++--
drivers/staging/irda/net/timer.c | 12 +-
drivers/staging/irda/net/wrapper.c | 3 +-
24 files changed, 450 insertions(+), 499 deletions(-)
--
2.14.2
^ permalink raw reply
* Re: [PATCH net-next] selftests: rtnetlink: add a small macsec test case
From: Sabrina Dubroca @ 2017-10-12 10:10 UTC (permalink / raw)
To: Florian Westphal; +Cc: netdev
In-Reply-To: <20171012091122.28133-1-fw@strlen.de>
2017-10-12, 11:11:22 +0200, Florian Westphal wrote:
> Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Just a small detail: the "ip macsec" commands actually use genetlink
and not rtnetlink.
--
Sabrina
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox