Saturday, January 9, 2010

smatch_scripts/show_unreachable.sh

Smatch prints out stuff like this:
net/rds/send.c +395 rds_send_acked_before(13) info: ignoring unreachable code.

The show_unreachable.sh script lets you browse through all of those pretty quickly.

It prints output like this:


=========================================================
drivers/mca/mca-device.c +69
{
struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);

return mca_bus->f.mca_read_pos(mca_dev, reg);

---------------------------------------------------------
return mca_dev->pos[reg];
}
EXPORT_SYMBOL(mca_device_read_pos);


You can scroll through an entire kernel worth of unreachable code in about 15 minutes.

released smatch 1.54

I am in Nairobi now. It costs less than $0.50 per hour to use internet here.

Nairobi has at one fibre connection to the outside world. It got connected last September. There are several others connecting soon. I used to follow the status closely but I have been mostly offline these past two years.

I released smatch 1.54. The announcement is here.

In some ways, I wish I had fixed it up a bit more before releasing. In other ways, release early and often.

I think the array overflow bugs from smatch 1.54 are interesting. The thing is that after a while all the interesting bugs get fixed and you are left with a discouraging pile of false positives. You have to have regular releases, with new checks because otherwise people think it's just false positives all the time.

[updated: I accidentally said it cost $1 to surf the net in Nairobi but I meant $.50 ]

Sunday, January 3, 2010

View patches from email

I have recently switched to using mutt to read email. When you are reading lkml you need a decent mail client and the only one I know of is mutt. It took a while to get used to the controls and to customize it but now I like it.

When someone emails a patch I like to view the context of the change, hence this view_full.sh script. The script assumes that your kernel source is in ~/progs/kernel/devel/. In mutt hit the '|' key and type ~/path/to/view_full.sh

After you exit vim it does patch -p1 -R to clean up.

#!/bin/bash -e

PATCH=$(mktemp)
tee $PATCH > /dev/null

files=$(grep ^+++ $PATCH | cut -f 1 | cut -b 5-)
cd ~/progs/kernel/devel/

if ! cat $PATCH | patch -p1 ; then
cat $PATCH | patch -R -p1
exit 1 # won't actually reach here because it's invoked with bash -e
# and the patch -R will fail.
fi

for file in $files ; do
line=$(grep -A1 "$file" $PATCH | tail -n 1 | cut -b 5- | cut -d ',' -f 1)
file=${file#*/}
vim $file +${line}
done
cat $PATCH | patch -p1 -R

rm $PATCH

One thing that is a bit annoying is that if you are in vim and type:
:! kchecker %
The line endings are messed up. The fix is to type:
:! kchecker % | less

Frist Post!!1!

I am in Lilongwe.

I start the bus ride to my brother's place in Kampala this evening. It takes 40+ hours to reach Dar Es Sala am. Then another day to Nairobi and then a third day to Kampala.

Once I did the trip in three days and three nights. There are no toilettes on the bus.

In Lilongwe, internet cafes charge $2 USD per hour. Last year most were charging $4 USD. Hopefully the price has gone down in Kampala as well.

Xuan Ji emailed me with an idea for improving smatch last night.


char buf[10];

if (x < sizeof(buf))
frob();
buf[x] = '\0';


The test for x implies that it's possible for x to be 10. Up to now smatch wasn't taking advantage of that. The old code just said that 'x' could be anything up to a bazillion. I made a new function get_fuzzy_max(x) that returns 10.

One problem is that if you say:

if (x == 10) {...

it assumes get_fuzzy_max() returns 11.