All of lore.kernel.org
 help / color / mirror / Atom feed
From: Murali Karicheri <m-karicheri2@ti.com>
To: Christopher Li <sparse@chrisli.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: How to fix CHECK warning: testing a 'safe expression' ?
Date: Thu, 18 Dec 2014 12:45:31 -0500	[thread overview]
Message-ID: <549312BB.40400@ti.com> (raw)
In-Reply-To: <CANeU7Q=85c8ehgCitG-Ujrr5O78V1yq9o=abJ8pwBBs0JOWAEg@mail.gmail.com>

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

  reply	other threads:[~2014-12-18 17:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2015-01-02 14:51 ` How to fix CHECK warning: testing a 'safe expression' Murali Karicheri
2015-01-02 22:20   ` Josh Triplett

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=549312BB.40400@ti.com \
    --to=m-karicheri2@ti.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sparse@chrisli.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 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.