From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6341882177714651136 Date: Sat, 15 Oct 2016 22:33:11 -0700 (PDT) From: Bhumika Goyal To: outreachy-kernel Message-Id: In-Reply-To: <20161016022145.GA2215@localhost> References: <20161016022145.GA2215@localhost> Subject: Re: Coccinelle Constification MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2763_1425429400.1476595991790" X-Google-Token: EJeijMAFraW0Nr4af9w0 X-Google-IP: 14.139.242.195 ------=_Part_2763_1425429400.1476595991790 Content-Type: multipart/alternative; boundary="----=_Part_2764_729016232.1476595991790" ------=_Part_2764_729016232.1476595991790 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hey Liz, Eva has already explained the process well but I would like to share my approach : 1. Firstly, I find all structures of the form static struct s i ={...}; by using the script: @r disable optional_qualifier@ identifier s,i; @@ * static struct s i ={...}; disable optional_qualifier is used here as we want to look only for the non-const structures. 2. Now pick a structure instance from a file and look how it is used in that file. If the structure's fields are not getting modified => it can be declared as const. You will have to analyze the usage carefully so that nothing is missed. Also, you can do a grep to be sure that all the referenced are covered. 3. After this you can write a Coccinelle script to constify all the instances that follows this particular pattern of usage. Make a rule in the script which matches the structure's reference that is justified for const declaration and stores the reference position. Look for the @ok@ rule in my scripts. Now make another rule which looks for any other reference other than the above one and stores this position as well. Look for @bad@ rule for this step. Next, add another rule @depends on !bad disable optional_qualifier@ that declares the structure as const. 4. After doing the changes compile the affected drivers and run size to get the size details of the affected file. I hope this helps :) Thanks, Bhumika ------=_Part_2764_729016232.1476595991790 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

Hey Liz,

Eva has already explained the process = well but I would like to
share my approach :

1. Firstly, I find a= ll structures of the form static struct s i =3D{...};
by using the scrip= t:
@r disable optional_qualifier@
identifier s,i;
@@
* static s= truct s i =3D{...};
disable optional_qualifier is used here as we want t= o look only for
the non-const structures.

2. Now pick a structure= instance from a file and look how it is used
in that file.
If the st= ructure's fields are not getting modified =3D> it can be
declared= as const.
You will have to analyze the usage carefully so that nothing = is missed.
Also, you can do a grep to be sure that all the referenced ar= e covered.

3. After this you can write a Coccinelle script to consti= fy all the
instances that follows this particular pattern of usage.
<= br>Make a rule in the script which matches the structure's reference th= at
is justified for const declaration and stores the reference position= .
Look for the @ok@ rule in my scripts.
Now make another rule which l= ooks for any other reference other
than the above one and stores this p= osition as well.
Look for @bad@ rule for this step.
Next, add another= rule @depends on !bad disable optional_qualifier@
that declares the str= ucture as const.

4. After doing the changes compile the affected dri= vers and run
size <affected_file_name> to get the size details of = the affected
file.

I hope this helps :)

Thanks,
Bhumika=
------=_Part_2764_729016232.1476595991790-- ------=_Part_2763_1425429400.1476595991790--