From: Dan Carpenter <dan.carpenter@linaro.org>
To: oe-kbuild@lists.linux.dev, Christian Eggers <ceggers@arri.de>
Cc: lkp@intel.com, oe-kbuild-all@lists.linux.dev,
linux-kernel@vger.kernel.org,
Arun Ramadoss <arun.ramadoss@microchip.com>,
Vladimir Oltean <olteanv@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Jacob Keller <jacob.e.keller@intel.com>
Subject: drivers/net/dsa/microchip/ksz_ptp.c:217 ksz_ptp_clock_register() warn: passing zero to 'PTR_ERR'
Date: Thu, 4 May 2023 09:48:58 +0300 [thread overview]
Message-ID: <00deb2fc-8489-4d9f-836b-6db828dbb61d@kili.mountain> (raw)
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: fa31fc82fb775445c176e576304c4098222f47f2
commit: eac1ea20261e1fac8ffbfb3b7da2d5e6b7c159e3 net: dsa: microchip: ptp: add the posix clock support
config: openrisc-randconfig-m031-20230430 (https://download.01.org/0day-ci/archive/20230504/202305041244.tDo9luPw-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Link: https://lore.kernel.org/r/202305041244.tDo9luPw-lkp@intel.com/
smatch warnings:
drivers/net/dsa/microchip/ksz_ptp.c:217 ksz_ptp_clock_register() warn: passing zero to 'PTR_ERR'
vim +/PTR_ERR +217 drivers/net/dsa/microchip/ksz_ptp.c
eac1ea20261e1f Christian Eggers 2023-01-10 186 int ksz_ptp_clock_register(struct dsa_switch *ds)
eac1ea20261e1f Christian Eggers 2023-01-10 187 {
eac1ea20261e1f Christian Eggers 2023-01-10 188 struct ksz_device *dev = ds->priv;
eac1ea20261e1f Christian Eggers 2023-01-10 189 struct ksz_ptp_data *ptp_data;
eac1ea20261e1f Christian Eggers 2023-01-10 190 int ret;
eac1ea20261e1f Christian Eggers 2023-01-10 191
eac1ea20261e1f Christian Eggers 2023-01-10 192 ptp_data = &dev->ptp_data;
eac1ea20261e1f Christian Eggers 2023-01-10 193 mutex_init(&ptp_data->lock);
eac1ea20261e1f Christian Eggers 2023-01-10 194
eac1ea20261e1f Christian Eggers 2023-01-10 195 ptp_data->caps.owner = THIS_MODULE;
eac1ea20261e1f Christian Eggers 2023-01-10 196 snprintf(ptp_data->caps.name, 16, "Microchip Clock");
eac1ea20261e1f Christian Eggers 2023-01-10 197 ptp_data->caps.max_adj = KSZ_MAX_DRIFT_CORR;
eac1ea20261e1f Christian Eggers 2023-01-10 198 ptp_data->caps.gettime64 = ksz_ptp_gettime;
eac1ea20261e1f Christian Eggers 2023-01-10 199 ptp_data->caps.settime64 = ksz_ptp_settime;
eac1ea20261e1f Christian Eggers 2023-01-10 200 ptp_data->caps.adjfine = ksz_ptp_adjfine;
eac1ea20261e1f Christian Eggers 2023-01-10 201 ptp_data->caps.adjtime = ksz_ptp_adjtime;
eac1ea20261e1f Christian Eggers 2023-01-10 202
eac1ea20261e1f Christian Eggers 2023-01-10 203 ret = ksz_ptp_start_clock(dev);
eac1ea20261e1f Christian Eggers 2023-01-10 204 if (ret)
eac1ea20261e1f Christian Eggers 2023-01-10 205 return ret;
eac1ea20261e1f Christian Eggers 2023-01-10 206
eac1ea20261e1f Christian Eggers 2023-01-10 207 /* Currently only P2P mode is supported. When 802_1AS bit is set, it
eac1ea20261e1f Christian Eggers 2023-01-10 208 * forwards all PTP packets to host port and none to other ports.
eac1ea20261e1f Christian Eggers 2023-01-10 209 */
eac1ea20261e1f Christian Eggers 2023-01-10 210 ret = ksz_rmw16(dev, REG_PTP_MSG_CONF1, PTP_TC_P2P | PTP_802_1AS,
eac1ea20261e1f Christian Eggers 2023-01-10 211 PTP_TC_P2P | PTP_802_1AS);
eac1ea20261e1f Christian Eggers 2023-01-10 212 if (ret)
eac1ea20261e1f Christian Eggers 2023-01-10 213 return ret;
eac1ea20261e1f Christian Eggers 2023-01-10 214
eac1ea20261e1f Christian Eggers 2023-01-10 215 ptp_data->clock = ptp_clock_register(&ptp_data->caps, dev->dev);
eac1ea20261e1f Christian Eggers 2023-01-10 216 if (IS_ERR_OR_NULL(ptp_data->clock))
eac1ea20261e1f Christian Eggers 2023-01-10 @217 return PTR_ERR(ptp_data->clock);
PTR_ERR(NULL) is success.
This code suggests that ptp_clock_register() is required. If it is
required then it should be enforced by the .config instead of leaving
the user with a module that can never be probed.
However, if it's not absolutely required and the user is allowed to
disable it in their .config then the way to write it is:
ptp_data->clock = ptp_clock_register(&ptp_data->caps, dev->dev);
if (IS_ERR(ptp_data->clock))
return PTR_ERR(ptp_data->clock);
Just add NULL checks before every ptp_data->clock dereference inside the
driver. (All the clock functions will be no-ops at that point so don't
worry about them).
See my blog for more info:
https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/
eac1ea20261e1f Christian Eggers 2023-01-10 218
eac1ea20261e1f Christian Eggers 2023-01-10 219 return 0;
eac1ea20261e1f Christian Eggers 2023-01-10 220 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
reply other threads:[~2023-05-04 6:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=00deb2fc-8489-4d9f-836b-6db828dbb61d@kili.mountain \
--to=dan.carpenter@linaro.org \
--cc=arun.ramadoss@microchip.com \
--cc=ceggers@arri.de \
--cc=f.fainelli@gmail.com \
--cc=jacob.e.keller@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=oe-kbuild@lists.linux.dev \
--cc=olteanv@gmail.com \
/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
all inboxes | Powered by JetHome®