hi folks,

I need help building my cocci-fu, currently Id have to call it cocci-oof

Ive prepped a patchset, to:

    register_chrdev_ids() aims to replace and deprecate
    register_chrdev_region() and alloc_chrdev_region()
    with a single function that works for both dynamic
    and static major numbers.

and am triyng to use spatch to do the user-callsite changes.
I have partial success, in that Ive gotten some rules to apply,

0 - is there a way to completely disable a rule with compile-syntax errors,
such that it doesnt have to be edited out ?  /* ... */ doesnt work.
is there an __END__ ala perl or could there be ?

1 - these 2 rules apply, but are simplistic, and wrong in some cases
(they disregard the if-then-else that should be removed)

My question with them is around the dev_t.
1st 'type's it, 2nd doesnt, both then use 'dev_t'
where a keyword {expression, identifier, etc} would go,
this doesnt blow up - whats the real interpretation ??

@ register_chrdev_region @ // depends on fs_h @
type dev_t;
//identifier devid;
dev_t devid;
expression ct;
identifier name;
@@

- register_chrdev_region(devid, ct, name)
+ register_chrdev_ids(&devid, ct, name)

@ alloc_chrdev_region @ // depends on fs_h @

// type dev_t;
dev_t devid;
expression minor; // ident didnt pick up constants
expression ct;
identifier name;
@@

- alloc_chrdev_region(&devid, minor, ct, name)
+ register_chrdev_ids(&devid, ct, name)


2- this rule wont apply - and is where Im mostly looking atm.

@ for_rtc_dev @ // ./drivers/rtc/rtc-dev.c

// typedef dev_t;  // "meta: parse error:  around = 'dev_t'
identifier err;
identifier rtc_devt;
expression maj, ct, nm;
@@
//      dev_t rtc_devt;   //  < -- VARY THIS LINE
        ...  // this doesnt matter
//      err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
-       err = alloc_chrdev_region(&rtc_devt, maj, ct, nm);
+       err = register_chrdev_ids(&rtc_devt, maj, ct, nm);
        if (err < 0) { ... }


linux-2.6.git]$ spatch -sp_file ../chrdev.cocci -partial_match
./drivers/rtc/rtc-dev.c

... (other rules elided) ...

HANDLING: ./drivers/rtc/rtc-dev.c
Empty list of bindings, I will restart from old env
Empty list of bindings, I will restart from old env
Empty list of bindings, I will restart from old env
Empty list of bindings, I will restart from old env
Empty list of bindings, I will restart from old env
partial matches
7[]{!wit 7[err --> id err]
       {wit 7[rtc_devt --> id rtc_devt]
           {wit 7[maj --> 0]
               {wit 7[ct --> RTC_DEV_MAX]
                   {wit 7[nm --> "rtc"]
                       {wit 7[_v --> for_rtc_dev:err = alloc_chrdev_region(
                        &for_rtc_dev:rtc_devt, for_rtc_dev:maj,
                        for_rtc_dev:ct, for_rtc_dev:nm);]{}}}}}}}


Empty list of bindings, I will restart from old env


If I remove the leading // on the  <-- VARY THIS LINE above,
I get no partial match, only 1 more empty-list-of-bindings.

This rule has 5 metavars, all are mentioned in the partial-matching output,
whats missing ?

I have 6 rules, and 6 empty-bindings, which seems to make sense.



3- this rule does work, at least in one case.
If I can generalize it properly, I might be finished...



@ for_fuse_cuse @  // this works
identifier rc, devt;
expression arg1, arg2;  // doesnt work as ident - lh_expr would if it existed.
expression MIN, CT, devname;
expression warn_on_this_expr;
identifier warn_on_this_ident;
@@

//      devt = MKDEV(arg->dev_major, arg->dev_minor);
        devt = MKDEV(arg1, arg2);
        ... when != devt  // no harm to purpose, may help other apps?
-        if (!MAJOR(devt))
//-              rc = alloc_chrdev_region(&devt, MINOR(devt), 1, devinfo.name);
-                rc = alloc_chrdev_region(&devt, MIN, CT, devname);
-        else
//-              rc = register_chrdev_region(devt, 1, devinfo.name);
-                rc = register_chrdev_region(devt, CT, devname);
+       rc = register_chrdev_ids(&devt, CT, devname);
        if (rc) {
                ...
        }

Attachment: chrdev.cocci
Description: Binary data

_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to