* How to fix CHECK warning: testing a 'safe expression'
@ 2014-12-16 18:23 Murali Karicheri
2014-12-17 16:18 ` How to fix CHECK warning: testing a 'safe expression' ? Murali Karicheri
2015-01-02 14:51 ` How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
0 siblings, 2 replies; 9+ messages in thread
From: Murali Karicheri @ 2014-12-16 18:23 UTC (permalink / raw)
To: netdev
netdev maintainers,
I got a comment to address CHECK warning and wondering how to address
'warning: testing a 'safe expression' which appears when using
IS_ERR_OR_NULL(foo)
where foo is defined as
struct foo_type *foo;
The foo get assigned only NULL or ERR_PTR(error code). So I believe the
usage is correct. But then how do I make the CHECK happy of its usage?
I have tried doing a grep on the current usage of IS_ERR_OR_NULL() and
found 276 of them causes this warning in the v3.18 version of the kernel
that I am using
$ grep -r "warning: testing a 'safe expression" * | wc -l
276
1) Can someone explain what this warning means?
2) Is it acceptable to post patches to netdev list with this warning?
3) if not, how this is expected to be fixed? Any example usage to fix
this warning will be helpful.
Thanks in advance for
--
Murali Karicheri
Linux Kernel, Texas Instruments
^ permalink raw reply [flat|nested] 9+ messages in thread
* How to fix CHECK warning: testing a 'safe expression' ?
2014-12-16 18:23 How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
@ 2014-12-17 16:18 ` Murali Karicheri
2014-12-17 18:49 ` Bjorn Helgaas
2015-01-02 14:51 ` How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
1 sibling, 1 reply; 9+ messages in thread
From: Murali Karicheri @ 2014-12-17 16:18 UTC (permalink / raw)
To: linux-pci
I am trying to address CHECK warnings in my driver and wondering how to
resolve 'warning: testing a 'safe expression' which appears when using
IS_ERR_OR_NULL(foo)
where foo is defined as
struct foo_type *foo;
The foo get assigned only NULL or ERR_PTR(error code). So I believe the
usage is correct. But then how do I make the CHECK happy of its usage?
I have tried a grep to check on the current usage of IS_ERR_OR_NULL()
and found 276 of them causes this warning in the v3.18 version of the
kernel that I am using
$ grep -r "warning: testing a 'safe expression" * | wc -l
276
Can someone help me undestand what this means and how to fix the same?
I run folling for CHECK
make C=2 CF="-D__CHECK_ENDIAN__" CHECK=sparse
Thanks in advance for your suggestions.
--
Murali Karicheri
Linux Kernel, Texas Instruments
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to fix CHECK warning: testing a 'safe expression' ?
2014-12-17 16:18 ` How to fix CHECK warning: testing a 'safe expression' ? Murali Karicheri
@ 2014-12-17 18:49 ` Bjorn Helgaas
2014-12-17 22:35 ` Murali Karicheri
0 siblings, 1 reply; 9+ messages in thread
From: Bjorn Helgaas @ 2014-12-17 18:49 UTC (permalink / raw)
To: Murali Karicheri; +Cc: linux-pci, Christopher Li, linux-kernel
[+cc Christopher, linux-kernel (this doesn't sound like a PCI-specific
question)]
On Wed, Dec 17, 2014 at 9:18 AM, Murali Karicheri <m-karicheri2@ti.com> wrote:
> I am trying to address CHECK warnings in my driver and wondering how to
> resolve 'warning: testing a 'safe expression' which appears when using
> IS_ERR_OR_NULL(foo)
>
> where foo is defined as
>
> struct foo_type *foo;
>
> The foo get assigned only NULL or ERR_PTR(error code). So I believe the
> usage is correct. But then how do I make the CHECK happy of its usage?
>
> I have tried a grep to check on the current usage of IS_ERR_OR_NULL() and
> found 276 of them causes this warning in the v3.18 version of the kernel
> that I am using
>
> $ grep -r "warning: testing a 'safe expression" * | wc -l
> 276
>
> Can someone help me undestand what this means and how to fix the same?
>
> I run folling for CHECK
>
> make C=2 CF="-D__CHECK_ENDIAN__" CHECK=sparse
If you can share your actual code or point to it in the tree, you
might get more specific help.
Bjorn
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to fix CHECK warning: testing a 'safe expression' ?
2014-12-17 18:49 ` Bjorn Helgaas
@ 2014-12-17 22:35 ` Murali Karicheri
2014-12-17 22:37 ` Murali Karicheri
0 siblings, 1 reply; 9+ messages in thread
From: Murali Karicheri @ 2014-12-17 22:35 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Christopher Li, linux-kernel
On 12/17/2014 01:49 PM, Bjorn Helgaas wrote:
> [+cc Christopher, linux-kernel (this doesn't sound like a PCI-specific
> question)]
>
> On Wed, Dec 17, 2014 at 9:18 AM, Murali Karicheri<m-karicheri2@ti.com> wrote:
>> I am trying to address CHECK warnings in my driver and wondering how to
>> resolve 'warning: testing a 'safe expression' which appears when using
>> IS_ERR_OR_NULL(foo)
>>
>> where foo is defined as
>>
>> struct foo_type *foo;
>>
>> The foo get assigned only NULL or ERR_PTR(error code). So I believe the
>> usage is correct. But then how do I make the CHECK happy of its usage?
>>
>> I have tried a grep to check on the current usage of IS_ERR_OR_NULL() and
>> found 276 of them causes this warning in the v3.18 version of the kernel
>> that I am using
>>
>> $ grep -r "warning: testing a 'safe expression" * | wc -l
>> 276
>>
>> Can someone help me undestand what this means and how to fix the same?
>>
>> I run folling for CHECK
>>
>> make C=2 CF="-D__CHECK_ENDIAN__" CHECK=sparse
>
> If you can share your actual code or point to it in the tree, you
> might get more specific help.
>
> Bjorn
For example I get
CHECK drivers/pci/host/pci-keystone.c
include/linux/err.h:40:16: warning: testing a 'safe expression'
Actually it is for IS_ERR_OR_NULL() call in the file which is the only
one call in the file.
--
Murali Karicheri
Linux Kernel, Texas Instruments
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to fix CHECK warning: testing a 'safe expression' ?
2014-12-17 22:35 ` Murali Karicheri
@ 2014-12-17 22:37 ` Murali Karicheri
2014-12-18 2:39 ` Christopher Li
0 siblings, 1 reply; 9+ messages in thread
From: Murali Karicheri @ 2014-12-17 22:37 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Christopher Li, linux-kernel
On 12/17/2014 05:35 PM, Murali Karicheri wrote:
> On 12/17/2014 01:49 PM, Bjorn Helgaas wrote:
>> [+cc Christopher, linux-kernel (this doesn't sound like a PCI-specific
>> question)]
>>
>> On Wed, Dec 17, 2014 at 9:18 AM, Murali Karicheri<m-karicheri2@ti.com>
>> wrote:
>>> I am trying to address CHECK warnings in my driver and wondering how to
>>> resolve 'warning: testing a 'safe expression' which appears when using
>>> IS_ERR_OR_NULL(foo)
>>>
>>> where foo is defined as
>>>
>>> struct foo_type *foo;
>>>
>>> The foo get assigned only NULL or ERR_PTR(error code). So I believe the
>>> usage is correct. But then how do I make the CHECK happy of its usage?
>>>
>>> I have tried a grep to check on the current usage of IS_ERR_OR_NULL()
>>> and
>>> found 276 of them causes this warning in the v3.18 version of the kernel
>>> that I am using
>>>
>>> $ grep -r "warning: testing a 'safe expression" * | wc -l
>>> 276
>>>
>>> Can someone help me undestand what this means and how to fix the same?
>>>
>>> I run folling for CHECK
>>>
>>> make C=2 CF="-D__CHECK_ENDIAN__" CHECK=sparse
>>
>> If you can share your actual code or point to it in the tree, you
>> might get more specific help.
>>
>> Bjorn
>
> For example I get
>
> CHECK drivers/pci/host/pci-keystone.c
> include/linux/err.h:40:16: warning: testing a 'safe expression'
>
> Actually it is for IS_ERR_OR_NULL() call in the file which is the only
> one call in the file.
>
Here is the code snippet for your convenience
struct device *dev = &pdev->dev;
struct keystone_pcie *ks_pcie;
struct pcie_port *pp;
struct resource *res;
void __iomem *reg_p;
struct phy *phy;
int ret = 0;
ks_pcie = devm_kzalloc(&pdev->dev, sizeof(*ks_pcie),
GFP_KERNEL);
if (!ks_pcie) {
dev_err(dev, "no memory for keystone pcie\n");
return -ENOMEM;
}
pp = &ks_pcie->pp;
/* initialize SerDes Phy if present */
phy = devm_phy_get(dev, "pcie-phy");
===> if (!IS_ERR_OR_NULL(phy)) {
ret = phy_init(phy);
if (ret < 0)
return ret;
}
--
Murali Karicheri
Linux Kernel, Texas Instruments
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to fix CHECK warning: testing a 'safe expression' ?
2014-12-17 22:37 ` Murali Karicheri
@ 2014-12-18 2:39 ` Christopher Li
2014-12-18 17:45 ` Murali Karicheri
0 siblings, 1 reply; 9+ messages in thread
From: Christopher Li @ 2014-12-18 2:39 UTC (permalink / raw)
To: Murali Karicheri; +Cc: Bjorn Helgaas, linux-pci, linux-kernel
On Thu, Dec 18, 2014 at 6:37 AM, Murali Karicheri <m-karicheri2@ti.com> wrote:
> if (!ks_pcie) {
> dev_err(dev, "no memory for keystone pcie\n");
> return -ENOMEM;
> }
> pp = &ks_pcie->pp;
>
> /* initialize SerDes Phy if present */
> phy = devm_phy_get(dev, "pcie-phy");
> ===> if (!IS_ERR_OR_NULL(phy)) {
> ret = phy_init(phy);
> if (ret < 0)
> return ret;
>
Hi,
Do you have a smaller stand alone test case which I can reproduce with sparse?
Thanks
Chris
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to fix CHECK warning: testing a 'safe expression' ?
2014-12-18 2:39 ` Christopher Li
@ 2014-12-18 17:45 ` Murali Karicheri
0 siblings, 0 replies; 9+ messages in thread
From: Murali Karicheri @ 2014-12-18 17:45 UTC (permalink / raw)
To: Christopher Li; +Cc: Bjorn Helgaas, linux-pci, linux-kernel
On 12/17/2014 09:39 PM, Christopher Li wrote:
> On Thu, Dec 18, 2014 at 6:37 AM, Murali Karicheri<m-karicheri2@ti.com> wrote:
>> if (!ks_pcie) {
>> dev_err(dev, "no memory for keystone pcie\n");
>> return -ENOMEM;
>> }
>> pp =&ks_pcie->pp;
>>
>> /* initialize SerDes Phy if present */
>> phy = devm_phy_get(dev, "pcie-phy");
>> ===> if (!IS_ERR_OR_NULL(phy)) {
>> ret = phy_init(phy);
>> if (ret< 0)
>> return ret;
>>
>
> Hi,
>
> Do you have a smaller stand alone test case which I can reproduce with sparse?
>
> Thanks
>
> Chris
Thanks Chris for responding.
You could add this piece of code for testing
struct foo {
int x;
int y;
};
static struct foo *func1(struct device *dev)
{
struct foo *fp;
fp = devm_kzalloc(dev, sizeof(*fp), GFP_KERNEL);
if (fp == NULL)
return ERR_PTR(-ENOMEM);
return fp;
}
And in one of your module in kernel add
struct foo *fp;
if (IS_ERR_OR_NULL(fp))
return -ENOMEM;
and do
make C=2 CF="-D__CHECK_ENDIAN__" CHECK=sparse
You will see the CHECK warning against your module as
include/linux/err.h:40:16: warning: testing a 'safe expression'
Hope this helps.
--
Murali Karicheri
Linux Kernel, Texas Instruments
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to fix CHECK warning: testing a 'safe expression'
2014-12-16 18:23 How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
2014-12-17 16:18 ` How to fix CHECK warning: testing a 'safe expression' ? Murali Karicheri
@ 2015-01-02 14:51 ` Murali Karicheri
2015-01-02 22:20 ` Josh Triplett
1 sibling, 1 reply; 9+ messages in thread
From: Murali Karicheri @ 2015-01-02 14:51 UTC (permalink / raw)
To: netdev, josh, linux-kernel
+ Josh
On 12/16/2014 01:23 PM, Murali Karicheri wrote:
> netdev maintainers,
>
> I got a comment to address CHECK warning and wondering how to address
> 'warning: testing a 'safe expression' which appears when using
> IS_ERR_OR_NULL(foo)
>
> where foo is defined as
>
> struct foo_type *foo;
>
> The foo get assigned only NULL or ERR_PTR(error code). So I believe the
> usage is correct. But then how do I make the CHECK happy of its usage?
>
> I have tried doing a grep on the current usage of IS_ERR_OR_NULL() and
> found 276 of them causes this warning in the v3.18 version of the kernel
> that I am using
>
> $ grep -r "warning: testing a 'safe expression" * | wc -l
> 276
>
> 1) Can someone explain what this warning means?
>
> 2) Is it acceptable to post patches to netdev list with this warning?
>
> 3) if not, how this is expected to be fixed? Any example usage to fix
> this warning will be helpful.
>
> Thanks in advance for
--
Murali Karicheri
Linux Kernel, Texas Instruments
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to fix CHECK warning: testing a 'safe expression'
2015-01-02 14:51 ` How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
@ 2015-01-02 22:20 ` Josh Triplett
0 siblings, 0 replies; 9+ messages in thread
From: Josh Triplett @ 2015-01-02 22:20 UTC (permalink / raw)
To: Murali Karicheri; +Cc: netdev, linux-kernel, linux-sparse
+linux-sparse
On Fri, Jan 02, 2015 at 09:51:25AM -0500, Murali Karicheri wrote:
> On 12/16/2014 01:23 PM, Murali Karicheri wrote:
> >netdev maintainers,
> >
> >I got a comment to address CHECK warning and wondering how to address
> >'warning: testing a 'safe expression' which appears when using
> >IS_ERR_OR_NULL(foo)
> >
> >where foo is defined as
> >
> >struct foo_type *foo;
> >
> >The foo get assigned only NULL or ERR_PTR(error code). So I believe the
> >usage is correct. But then how do I make the CHECK happy of its usage?
> >
> >I have tried doing a grep on the current usage of IS_ERR_OR_NULL() and
> >found 276 of them causes this warning in the v3.18 version of the kernel
> >that I am using
> >
> >$ grep -r "warning: testing a 'safe expression" * | wc -l
> >276
> >
> >1) Can someone explain what this warning means?
> >
> >2) Is it acceptable to post patches to netdev list with this warning?
> >
> >3) if not, how this is expected to be fixed? Any example usage to fix
> >this warning will be helpful.
> >
> >Thanks in advance for
>
>
> --
> Murali Karicheri
> Linux Kernel, Texas Instruments
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-01-02 22:20 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-16 18:23 How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
2014-12-17 16:18 ` How to fix CHECK warning: testing a 'safe expression' ? Murali Karicheri
2014-12-17 18:49 ` Bjorn Helgaas
2014-12-17 22:35 ` Murali Karicheri
2014-12-17 22:37 ` Murali Karicheri
2014-12-18 2:39 ` Christopher Li
2014-12-18 17:45 ` Murali Karicheri
2015-01-02 14:51 ` How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
2015-01-02 22:20 ` Josh Triplett
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.