From: Dan Carpenter <dan.carpenter@oracle.com>
To: Richard Cochran <richardcochran@gmail.com>,
Ganesh Goudar <ganeshgr@chelsio.com>,
Atul Gupta <atul.gupta@chelsio.com>
Cc: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/2 net] ptp: fix error codes in ptp_clock_register()
Date: Mon, 10 Jul 2017 10:11:37 +0300 [thread overview]
Message-ID: <20170710071137.ui2fhjkqzjqhkopz@mwanda> (raw)
The ptp_clock_register() function returns NULL when it's #ifdefed out
because CONFIG_PTP_1588_CLOCK is disabled. Otherwise, it's intended to
return error pointers. Unfortunately, there are a couple paths where we
forget to set the error code. It means that we could result in NULL
pointer dereferences in the callers.
Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index b77435783ef3..a50e96143a25 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -190,7 +190,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
struct device *parent)
{
struct ptp_clock *ptp;
- int err = 0, index, major = MAJOR(ptp_devt);
+ int err, index, major = MAJOR(ptp_devt);
if (info->n_alarm > PTP_MAX_ALARMS)
return ERR_PTR(-EINVAL);
@@ -225,8 +225,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
ptp->dev = device_create_with_groups(ptp_class, parent, ptp->devid,
ptp, ptp->pin_attr_groups,
"ptp%d", ptp->index);
- if (IS_ERR(ptp->dev))
+ if (IS_ERR(ptp->dev)) {
+ err = PTR_ERR(ptp->dev);
goto no_device;
+ }
/* Register a new PPS source. */
if (info->pps) {
@@ -238,6 +240,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS);
if (!ptp->pps_source) {
pr_err("failed to register pps source\n");
+ err = -ENOMEM;
goto no_pps;
}
}
next reply other threads:[~2017-07-10 7:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-10 7:11 Dan Carpenter [this message]
2017-07-10 7:16 ` [PATCH 2/2 net] cxgb4: ptp_clock_register() returns error pointers Dan Carpenter
2017-07-10 9:56 ` Richard Cochran
2017-07-10 9:21 ` [PATCH 1/2 net] ptp: fix error codes in ptp_clock_register() Richard Cochran
2017-07-10 9:38 ` Dan Carpenter
2017-07-10 9:48 ` Richard Cochran
2017-07-10 10:29 ` Dan Carpenter
2017-07-10 11:02 ` Richard Cochran
2017-07-10 9:34 ` Richard Cochran
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=20170710071137.ui2fhjkqzjqhkopz@mwanda \
--to=dan.carpenter@oracle.com \
--cc=atul.gupta@chelsio.com \
--cc=ganeshgr@chelsio.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@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