From: Dan Carpenter <dan.carpenter@oracle.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Russell King - ARM Linux admin <linux@armlinux.org.uk>,
Michael Walle <michael@walle.cc>,
Heiner Kallweit <hkallweit1@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net-next] net: phy: icplus: Call phy_restore_page() when phy_select_page() fails
Date: Thu, 18 Feb 2021 00:24:12 +0300 [thread overview]
Message-ID: <20210217212411.GC2087@kadam> (raw)
In-Reply-To: <YC1NKO2HznLC887f@lunn.ch>
On Wed, Feb 17, 2021 at 06:06:48PM +0100, Andrew Lunn wrote:
> > I'm wondering whether we need to add __acquires() and __releases()
> > annotations to some of these functions so that sparse can catch
> > these cases. Thoughts?
>
> Hi Russell
>
> The more tools we have for catching locking problems the better.
> Jakubs patchwork bot should then catch them when a patch is submitted,
> if the developer did not run sparse themselves.
Here is how I wrote the check for Smatch. The code in the kernel looks
like:
oldpage = phy_select_page(phydev, 0x0007);
...
phy_restore_page(phydev, oldpage, 0);
So what I said is that if phy_select_page() returns an error code then
set "phydev" to &selected state. Then if we call phy_restore_page()
set it to &undefined. When we hit a return, check if we have any
"phydev" variables can possibly be in &selected state and print a
warning.
The code is below.
regards,
dan carpenter
#include "smatch.h"
#include "smatch_slist.h"
static int my_id;
STATE(selected);
static sval_t err_min = { .type = &int_ctype, .value = -4095 };
static sval_t err_max = { .type = &int_ctype, .value = -1 };
static void match_phy_select_page(struct expression *expr, const char *name, struct symbol *sym, void *data)
{
set_state(my_id, name, sym, &selected);
}
static void match_phy_restore_page(struct expression *expr, const char *name, struct symbol *sym, void *data)
{
set_state(my_id, name, sym, &undefined);
}
static void match_return(struct expression *expr)
{
struct sm_state *sm;
FOR_EACH_MY_SM(my_id, __get_cur_stree(), sm) {
if (slist_has_state(sm->possible, &selected)) {
sm_warning("phy_select_page() requires restore on error");
return;
}
} END_FOR_EACH_SM(sm);
}
void check_phy_select_page_fail(int id)
{
if (option_project != PROJ_KERNEL)
return;
my_id = id;
return_implies_param_key("phy_select_page", err_min, err_max,
&match_phy_select_page, 0, "$", NULL);
add_function_param_key_hook("phy_restore_page", &match_phy_restore_page,
0, "$", NULL);
add_hook(&match_return, RETURN_HOOK);
}
prev parent reply other threads:[~2021-02-17 21:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-17 6:17 [PATCH net-next] net: phy: icplus: Call phy_restore_page() when phy_select_page() fails Dan Carpenter
2021-02-17 7:52 ` Michael Walle
2021-02-17 10:04 ` Russell King - ARM Linux admin
2021-02-17 10:12 ` Michael Walle
2021-02-17 10:21 ` Russell King - ARM Linux admin
2021-02-17 14:28 ` Dan Carpenter
2021-02-17 15:06 ` Russell King - ARM Linux admin
2021-02-17 15:33 ` Russell King - ARM Linux admin
2021-02-17 17:06 ` Andrew Lunn
2021-02-17 21:24 ` Dan Carpenter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210217212411.GC2087@kadam \
--to=dan.carpenter@oracle.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=hkallweit1@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=michael@walle.cc \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).