linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 net-next] ptp: Fix pass zero to ERR_PTR() in ptp_clock_register
@ 2018-11-23  1:54 YueHaibing
  2018-11-23 16:37 ` Richard Cochran
  2018-11-24  2:04 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: YueHaibing @ 2018-11-23  1:54 UTC (permalink / raw)
  To: davem, richardcochran, dmitry.torokhov; +Cc: linux-kernel, netdev, YueHaibing

Fix smatch warning:

drivers/ptp/ptp_clock.c:298 ptp_clock_register() warn:
 passing zero to 'ERR_PTR'

'err' should be set while device_create_with_groups and
pps_register_source fails

Fixes: 85a66e550195 ("ptp: create "pins" together with the rest of attributes")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
v2: fix wrong 'err' set while pps_register_source fails
---
 drivers/ptp/ptp_clock.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 40fda23..8a81eec 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -252,8 +252,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) {
@@ -264,6 +266,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
 		pps.owner = info->owner;
 		ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS);
 		if (!ptp->pps_source) {
+			err = -EINVAL;
 			pr_err("failed to register pps source\n");
 			goto no_pps;
 		}
-- 
2.7.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 net-next] ptp: Fix pass zero to ERR_PTR() in ptp_clock_register
  2018-11-23  1:54 [PATCH v2 net-next] ptp: Fix pass zero to ERR_PTR() in ptp_clock_register YueHaibing
@ 2018-11-23 16:37 ` Richard Cochran
  2018-11-26 10:20   ` YueHaibing
  2018-11-24  2:04 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Richard Cochran @ 2018-11-23 16:37 UTC (permalink / raw)
  To: YueHaibing; +Cc: davem, dmitry.torokhov, linux-kernel, netdev

On Fri, Nov 23, 2018 at 09:54:55AM +0800, YueHaibing wrote:
> @@ -264,6 +266,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
>  		pps.owner = info->owner;
>  		ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS);
>  		if (!ptp->pps_source) {
> +			err = -EINVAL;

Bonus points:  The function, pps_register_source(), keeps error codes
in a local variable, but it does not make use of the code.  There are
only five callers of that function, and so it would be nice to let
pps_register_source() return the error code.

For the present patch:

Acked-by: Richard Cochran <richardcochran@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 net-next] ptp: Fix pass zero to ERR_PTR() in ptp_clock_register
  2018-11-23  1:54 [PATCH v2 net-next] ptp: Fix pass zero to ERR_PTR() in ptp_clock_register YueHaibing
  2018-11-23 16:37 ` Richard Cochran
@ 2018-11-24  2:04 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2018-11-24  2:04 UTC (permalink / raw)
  To: yuehaibing; +Cc: richardcochran, dmitry.torokhov, linux-kernel, netdev

From: YueHaibing <yuehaibing@huawei.com>
Date: Fri, 23 Nov 2018 09:54:55 +0800

> Fix smatch warning:
> 
> drivers/ptp/ptp_clock.c:298 ptp_clock_register() warn:
>  passing zero to 'ERR_PTR'
> 
> 'err' should be set while device_create_with_groups and
> pps_register_source fails
> 
> Fixes: 85a66e550195 ("ptp: create "pins" together with the rest of attributes")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 net-next] ptp: Fix pass zero to ERR_PTR() in ptp_clock_register
  2018-11-23 16:37 ` Richard Cochran
@ 2018-11-26 10:20   ` YueHaibing
  0 siblings, 0 replies; 4+ messages in thread
From: YueHaibing @ 2018-11-26 10:20 UTC (permalink / raw)
  To: Richard Cochran; +Cc: davem, dmitry.torokhov, linux-kernel, netdev



On 2018/11/24 0:37, Richard Cochran wrote:
> On Fri, Nov 23, 2018 at 09:54:55AM +0800, YueHaibing wrote:
>> @@ -264,6 +266,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
>>  		pps.owner = info->owner;
>>  		ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS);
>>  		if (!ptp->pps_source) {
>> +			err = -EINVAL;
> 
> Bonus points:  The function, pps_register_source(), keeps error codes
> in a local variable, but it does not make use of the code.  There are
> only five callers of that function, and so it would be nice to let
> pps_register_source() return the error code.

Ok, I will post a new patch to do it.

> 
> For the present patch:
> 
> Acked-by: Richard Cochran <richardcochran@gmail.com>
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-11-26 10:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-23  1:54 [PATCH v2 net-next] ptp: Fix pass zero to ERR_PTR() in ptp_clock_register YueHaibing
2018-11-23 16:37 ` Richard Cochran
2018-11-26 10:20   ` YueHaibing
2018-11-24  2:04 ` David Miller

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).