Commit 2ce13cf2 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Kill redundant redundant null checks

I caught one during a review and figured I might as well sweep the whole
tree, so this patch was created using Coccinelle and the following steps:

    $ cat >check_obj.cocci <<EOF
    @@
    expression obj, magic;
    @@

    if (obj != NULL) {
    - CHECK_OBJ_NOTNULL(obj, magic);
    + CHECK_OBJ(obj, magic);
    ...
    }
    EOF
    $ spatch --dir . --in-place --sp-file check_obj.cocci

This is my fourth semantic patch, I wouldn't mind checking them in to
have them handy in the repo to semi-automate code polish every now and
then. For example in a /tools/cocci directory. This way people could
study them or use them in their out-of-tree projects like VMODs or VUTs.
parent 23c918ed
......@@ -127,7 +127,7 @@ VDP_close(struct req *req)
if (vdc->retval >= 0)
AN(vdpe);
if (vdpe != NULL) {
CHECK_OBJ_NOTNULL(vdpe, VDP_ENTRY_MAGIC);
CHECK_OBJ(vdpe, VDP_ENTRY_MAGIC);
VTAILQ_REMOVE(&vdc->vdp, vdpe, list);
if (vdpe->vdp->fini != NULL)
AZ(vdpe->vdp->fini(req, &vdpe->priv));
......
......@@ -503,7 +503,7 @@ VRT_u_bereq_body(VRT_CTX)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
if (ctx->bo->req != NULL) {
CHECK_OBJ_NOTNULL(ctx->bo->req, REQ_MAGIC);
CHECK_OBJ(ctx->bo->req, REQ_MAGIC);
ctx->bo->req = NULL;
ObjSetState(ctx->bo->wrk,
ctx->bo->fetch_objcore, BOS_REQ_DONE);
......
......@@ -436,7 +436,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
INIT_OBJ(&ctx, VRT_CTX_MAGIC);
if (req != NULL) {
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(req->vcl, VCL_MAGIC);
VCL_Req2Ctx(&ctx, req);
......
......@@ -413,7 +413,7 @@ VEV_Once(struct vev_root *evb)
tmo = INFTIM;
e = binheap_root(evb->binheap);
if (e != NULL) {
CHECK_OBJ_NOTNULL(e, VEV_MAGIC);
CHECK_OBJ(e, VEV_MAGIC);
assert(e->__binheap_idx == BINHEAP_NOIDX + 1);
t = VTIM_mono();
if (e->__when <= t)
......
......@@ -629,7 +629,7 @@ vex_print(const struct vex *vex, int indent)
fprintf(stderr, "%*s%s", indent, "", vxp_tnames[vex->tok]);
if (vex->lhs != NULL) {
CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC);
CHECK_OBJ(vex->lhs, VEX_LHS_MAGIC);
AN(vex->lhs->tags);
fprintf(stderr, " lhs=");
if (vex->lhs->level >= 0)
......
......@@ -402,7 +402,7 @@ shard_get_key(VRT_CTX, const struct vmod_directors_shard_param *p)
switch (p->by) {
case BY_HASH:
if (ctx->bo) {
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
CHECK_OBJ(ctx->bo, BUSYOBJ_MAGIC);
return (vbe32dec(ctx->bo->digest));
}
/* FALLTHROUGH */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment