All of lore.kernel.org
 help / color / mirror / Atom feed
* Proposal for a new checkpatch check; matching _set_drvdata() & _get_drvdata()
@ 2020-11-19 14:09 Alexandru Ardelean
  2020-11-19 15:16 ` Andy Shevchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Alexandru Ardelean @ 2020-11-19 14:09 UTC (permalink / raw)
  To: apw, joe, LKML; +Cc: Alexandru Ardelean, Andy Shevchenko

Hey,

So, I stumbled on a new check that could be added to checkpatch.
Since it's in Perl, I'm reluctant to try it.

Seems many drivers got to a point where they now call (let's say)
spi_set_drvdata(), but never access that information via
spi_get_drvdata().
Reasons for this seem to be:
1. They got converted to device-managed functions and there is no
longer a remove hook to require the _get_drvdata() access
2. They look like they were copied from a driver that had a
_set_drvdata() and when the code got finalized, the _set_drvdata() was
omitted

There are a few false positives that I can notice at a quick look,
like the data being set via some xxx_set_drvdata() and retrieved via a
dev_get_drvdata().
I think checkpatch reporting these as well would be acceptable simply
from a reviewability perspective.

I did a shell script to quickly check these. See below.
It's pretty badly written but it is enough for me to gather a list.
And I wrote it in 5 minutes :P
I initially noticed this in some IIO drivers, and then I suspected
that this may be more widespread.

The shell script gathers a list of xxx_set_drvdata() functions then
greps through all files and also checks if there are any matching
xxx_get_drvdata().

Thanks
Alex

Shell script:
-----------------------------------------------------------------------
#!/bin/bash

fns1=$(git grep _set_drvdata | cut -d: -f2 | cut -d'(' -f1 | sort -u)

for fn in $fns1 ; do
        if [ "$fn" == "//pci_set_drvdata" ] ; then
                continue
        fi
        if [ "$fn" == '``dev_set_drvdata' ] ; then
                continue
        fi
        if [ "$fn" == '"pci_set_drvdata' ] ; then
                continue
        fi
        if [[ "$fn" == *"_set_drvdata" ]]; then
                fns2="$fns2 $fn"
        fi
done

fns1=$(echo $fns2 | tr ' ' '\n' | sort -u | tr '\n' ' ')

for fn in $fns1 ; do
        get_fn=$(echo $fn | sed 's/_set_/_get_/g')

        echo "Matching $fn - $get_fn"
        for file in $(git grep $fn | cut -d: -f1 | sort -u) ; do
                if ! grep -q $get_fn $file ; then
                        echo "   Maybe $file"
                fi
        done
done
-----------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-11-20 13:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 14:09 Proposal for a new checkpatch check; matching _set_drvdata() & _get_drvdata() Alexandru Ardelean
2020-11-19 15:16 ` Andy Shevchenko
2020-11-20  0:11   ` Joe Perches
2020-11-20  0:11     ` [Cocci] " Joe Perches
2020-11-20 10:47     ` Julia Lawall
2020-11-20 10:47       ` Julia Lawall
2020-11-20 11:54       ` Alexandru Ardelean
2020-11-20 11:54         ` Alexandru Ardelean
2020-11-20 11:57         ` Julia Lawall
2020-11-20 11:57           ` Julia Lawall
2020-11-20 11:58           ` Alexandru Ardelean
2020-11-20 11:58             ` Alexandru Ardelean
2020-11-20 13:16         ` Lars-Peter Clausen
2020-11-20 13:16           ` Lars-Peter Clausen
2020-11-20 13:27           ` Alexandru Ardelean
2020-11-20 13:27             ` Alexandru Ardelean

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.