From d2d8fbebb86eb682fc9507a884e80ff5e6086f03 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 18 Nov 2010 10:07:48 -0800 Subject: [PATCH] dpif: Use caller-provided dpif_class in dp_register_provider(). I don't see a reason here to copy the dpif_class instead of using the pointer provided by the caller. Using the caller's pointer allows the caller to compare a dpif's 'class' member against the address of its class structure, which seems like a reasonable thing to do. --- lib/dpif.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/dpif.c b/lib/dpif.c index e117bdf9..30384196 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -50,7 +50,7 @@ static const struct dpif_class *base_dpif_classes[] = { }; struct registered_dpif_class { - struct dpif_class dpif_class; + const struct dpif_class *dpif_class; int refcount; }; static struct shash dpif_classes = SHASH_INITIALIZER(&dpif_classes); @@ -97,8 +97,8 @@ dp_run(void) struct shash_node *node; SHASH_FOR_EACH(node, &dpif_classes) { const struct registered_dpif_class *registered_class = node->data; - if (registered_class->dpif_class.run) { - registered_class->dpif_class.run(); + if (registered_class->dpif_class->run) { + registered_class->dpif_class->run(); } } } @@ -113,8 +113,8 @@ dp_wait(void) struct shash_node *node; SHASH_FOR_EACH(node, &dpif_classes) { const struct registered_dpif_class *registered_class = node->data; - if (registered_class->dpif_class.wait) { - registered_class->dpif_class.wait(); + if (registered_class->dpif_class->wait) { + registered_class->dpif_class->wait(); } } } @@ -133,8 +133,7 @@ dp_register_provider(const struct dpif_class *new_class) } registered_class = xmalloc(sizeof *registered_class); - memcpy(®istered_class->dpif_class, new_class, - sizeof registered_class->dpif_class); + registered_class->dpif_class = new_class; registered_class->refcount = 0; shash_add(&dpif_classes, new_class->type, registered_class); @@ -182,7 +181,7 @@ dp_enumerate_types(struct svec *types) SHASH_FOR_EACH(node, &dpif_classes) { const struct registered_dpif_class *registered_class = node->data; - svec_add(types, registered_class->dpif_class.type); + svec_add(types, registered_class->dpif_class->type); } } @@ -208,7 +207,7 @@ dp_enumerate_names(const char *type, struct svec *names) return EAFNOSUPPORT; } - dpif_class = ®istered_class->dpif_class; + dpif_class = registered_class->dpif_class; error = dpif_class->enumerate ? dpif_class->enumerate(names) : 0; if (error) { @@ -259,7 +258,7 @@ do_open(const char *name, const char *type, bool create, struct dpif **dpifp) goto exit; } - error = registered_class->dpif_class.open(name, type, create, &dpif); + error = registered_class->dpif_class->open(name, type, create, &dpif); if (!error) { registered_class->refcount++; } -- 2.30.2