mirror of
https://github.com/openvswitch/ovs
synced 2025-08-22 09:58:01 +00:00
treewide: Add ovs_assert
to check for null pointers.
This patch adds an assortment of `ovs_assert` statements to check for null pointers. We use assertions since it should be impossible for any of these pointers to be NULL. Reviewed-by: Simon Horman <simon.horman@corigine.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: James Raphael Tiovalen <jamestiotio@gmail.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
parent
40546cd6e5
commit
bc79a7bf03
@ -175,6 +175,7 @@ dp_packet_new_with_headroom(size_t size, size_t headroom)
|
|||||||
struct dp_packet *
|
struct dp_packet *
|
||||||
dp_packet_clone(const struct dp_packet *buffer)
|
dp_packet_clone(const struct dp_packet *buffer)
|
||||||
{
|
{
|
||||||
|
ovs_assert(buffer);
|
||||||
return dp_packet_clone_with_headroom(buffer, 0);
|
return dp_packet_clone_with_headroom(buffer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +147,8 @@ odp_set_ipv4(struct dp_packet *packet, const struct ovs_key_ipv4 *key,
|
|||||||
uint8_t new_tos;
|
uint8_t new_tos;
|
||||||
uint8_t new_ttl;
|
uint8_t new_ttl;
|
||||||
|
|
||||||
|
ovs_assert(nh);
|
||||||
|
|
||||||
if (mask->ipv4_src) {
|
if (mask->ipv4_src) {
|
||||||
ip_src_nh = get_16aligned_be32(&nh->ip_src);
|
ip_src_nh = get_16aligned_be32(&nh->ip_src);
|
||||||
new_ip_src = key->ipv4_src | (ip_src_nh & ~mask->ipv4_src);
|
new_ip_src = key->ipv4_src | (ip_src_nh & ~mask->ipv4_src);
|
||||||
@ -287,6 +289,8 @@ set_arp(struct dp_packet *packet, const struct ovs_key_arp *key,
|
|||||||
{
|
{
|
||||||
struct arp_eth_header *arp = dp_packet_l3(packet);
|
struct arp_eth_header *arp = dp_packet_l3(packet);
|
||||||
|
|
||||||
|
ovs_assert(arp);
|
||||||
|
|
||||||
if (!mask) {
|
if (!mask) {
|
||||||
arp->ar_op = key->arp_op;
|
arp->ar_op = key->arp_op;
|
||||||
arp->ar_sha = key->arp_sha;
|
arp->ar_sha = key->arp_sha;
|
||||||
|
@ -112,7 +112,7 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change)
|
|||||||
if (parsed) {
|
if (parsed) {
|
||||||
const struct ifinfomsg *ifinfo;
|
const struct ifinfomsg *ifinfo;
|
||||||
|
|
||||||
ifinfo = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifinfo);
|
ifinfo = ofpbuf_at_assert(buf, NLMSG_HDRLEN, sizeof *ifinfo);
|
||||||
|
|
||||||
/* Wireless events can be spammy and cause a
|
/* Wireless events can be spammy and cause a
|
||||||
* lot of unnecessary churn and CPU load in
|
* lot of unnecessary churn and CPU load in
|
||||||
@ -175,7 +175,7 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change)
|
|||||||
if (parsed) {
|
if (parsed) {
|
||||||
const struct ifaddrmsg *ifaddr;
|
const struct ifaddrmsg *ifaddr;
|
||||||
|
|
||||||
ifaddr = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifaddr);
|
ifaddr = ofpbuf_at_assert(buf, NLMSG_HDRLEN, sizeof *ifaddr);
|
||||||
|
|
||||||
change->nlmsg_type = nlmsg->nlmsg_type;
|
change->nlmsg_type = nlmsg->nlmsg_type;
|
||||||
change->if_index = ifaddr->ifa_index;
|
change->if_index = ifaddr->ifa_index;
|
||||||
|
@ -265,7 +265,7 @@ void *
|
|||||||
shash_find_and_delete_assert(struct shash *sh, const char *name)
|
shash_find_and_delete_assert(struct shash *sh, const char *name)
|
||||||
{
|
{
|
||||||
void *data = shash_find_and_delete(sh, name);
|
void *data = shash_find_and_delete(sh, name);
|
||||||
ovs_assert(data != NULL);
|
ovs_assert(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1131,6 +1131,8 @@ static void
|
|||||||
ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
|
ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
|
||||||
struct jsonrpc_msg *request)
|
struct jsonrpc_msg *request)
|
||||||
{
|
{
|
||||||
|
ovs_assert(db);
|
||||||
|
|
||||||
/* Check for duplicate ID. */
|
/* Check for duplicate ID. */
|
||||||
size_t hash = json_hash(request->id, 0);
|
size_t hash = json_hash(request->id, 0);
|
||||||
struct ovsdb_jsonrpc_trigger *t
|
struct ovsdb_jsonrpc_trigger *t
|
||||||
@ -1391,6 +1393,8 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
|
|||||||
enum ovsdb_monitor_version version,
|
enum ovsdb_monitor_version version,
|
||||||
const struct json *request_id)
|
const struct json *request_id)
|
||||||
{
|
{
|
||||||
|
ovs_assert(db);
|
||||||
|
|
||||||
struct ovsdb_jsonrpc_monitor *m = NULL;
|
struct ovsdb_jsonrpc_monitor *m = NULL;
|
||||||
struct ovsdb_monitor *dbmon = NULL;
|
struct ovsdb_monitor *dbmon = NULL;
|
||||||
struct json *monitor_id, *monitor_requests;
|
struct json *monitor_id, *monitor_requests;
|
||||||
|
@ -1322,6 +1322,7 @@ ovsdb_monitor_table_add_select(struct ovsdb_monitor *dbmon,
|
|||||||
struct ovsdb_monitor_table * mt;
|
struct ovsdb_monitor_table * mt;
|
||||||
|
|
||||||
mt = shash_find_data(&dbmon->tables, table->schema->name);
|
mt = shash_find_data(&dbmon->tables, table->schema->name);
|
||||||
|
ovs_assert(mt);
|
||||||
mt->select |= select;
|
mt->select |= select;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1706,6 +1707,8 @@ ovsdb_monitor_hash(const struct ovsdb_monitor *dbmon, size_t basis)
|
|||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
struct ovsdb_monitor_table *mt = nodes[i]->data;
|
struct ovsdb_monitor_table *mt = nodes[i]->data;
|
||||||
|
|
||||||
|
ovs_assert(mt);
|
||||||
|
|
||||||
basis = hash_pointer(mt->table, basis);
|
basis = hash_pointer(mt->table, basis);
|
||||||
basis = hash_3words(mt->select, mt->n_columns, basis);
|
basis = hash_3words(mt->select, mt->n_columns, basis);
|
||||||
|
|
||||||
|
@ -2262,6 +2262,7 @@ sset_from_json(struct sset *sset, const struct json *array)
|
|||||||
|
|
||||||
sset_clear(sset);
|
sset_clear(sset);
|
||||||
|
|
||||||
|
ovs_assert(array);
|
||||||
ovs_assert(array->type == JSON_ARRAY);
|
ovs_assert(array->type == JSON_ARRAY);
|
||||||
for (i = 0; i < array->array.n; i++) {
|
for (i = 0; i < array->array.n; i++) {
|
||||||
const struct json *elem = array->array.elems[i];
|
const struct json *elem = array->array.elems[i];
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
VLOG_DEFINE_THIS_MODULE(transaction);
|
VLOG_DEFINE_THIS_MODULE(transaction);
|
||||||
|
|
||||||
@ -576,6 +577,7 @@ ovsdb_txn_update_weak_refs(struct ovsdb_txn *txn OVS_UNUSED,
|
|||||||
dst_row = CONST_CAST(struct ovsdb_row *,
|
dst_row = CONST_CAST(struct ovsdb_row *,
|
||||||
ovsdb_table_get_row(weak->dst_table, &weak->dst));
|
ovsdb_table_get_row(weak->dst_table, &weak->dst));
|
||||||
|
|
||||||
|
ovs_assert(dst_row);
|
||||||
ovs_assert(!ovsdb_row_find_weak_ref(dst_row, weak));
|
ovs_assert(!ovsdb_row_find_weak_ref(dst_row, weak));
|
||||||
hmap_insert(&dst_row->dst_refs, &weak->dst_node,
|
hmap_insert(&dst_row->dst_refs, &weak->dst_node,
|
||||||
ovsdb_weak_ref_hash(weak));
|
ovsdb_weak_ref_hash(weak));
|
||||||
|
@ -820,6 +820,7 @@ vsctl_context_populate_cache(struct ctl_context *ctx)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
br = shash_find_data(&vsctl_ctx->bridges, br_cfg->name);
|
br = shash_find_data(&vsctl_ctx->bridges, br_cfg->name);
|
||||||
|
ovs_assert(br);
|
||||||
for (j = 0; j < br_cfg->n_ports; j++) {
|
for (j = 0; j < br_cfg->n_ports; j++) {
|
||||||
struct ovsrec_port *port_cfg = br_cfg->ports[j];
|
struct ovsrec_port *port_cfg = br_cfg->ports[j];
|
||||||
struct vsctl_port *port;
|
struct vsctl_port *port;
|
||||||
|
@ -1065,6 +1065,7 @@ vtep_ctl_context_populate_cache(struct ctl_context *ctx)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name);
|
ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name);
|
||||||
|
ovs_assert(ps);
|
||||||
for (j = 0; j < ps_cfg->n_ports; j++) {
|
for (j = 0; j < ps_cfg->n_ports; j++) {
|
||||||
struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
|
struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
|
||||||
struct vtep_ctl_port *port;
|
struct vtep_ctl_port *port;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user