linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] [PATCH] can: fix handling of unmodifiable configuration options
@ 2016-03-08 17:13 Oliver Hartkopp
  2016-03-08 18:22 ` Oliver Hartkopp
  2016-03-09  9:27 ` Ramesh Shanmugasundaram
  0 siblings, 2 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2016-03-08 17:13 UTC (permalink / raw)
  To: linux-can; +Cc: ramesh.shanmugasundaram, Oliver Hartkopp, linux-stable 3 . 16+

As described in 'can: m_can: tag current CAN FD controllers as non-ISO'
(6cfda7fbebe) it is possible to define fixed configuration options by
setting the according bit in 'ctrlmode' and clear it in 'ctrlmode_supported'.
This leads to the incovenience that the fixed configuration can not be passed
by netlink (ip tool) even when it has the correct value (e.g. non-ISO, FD).

This patch fixes that issue and allows fixed set bit values to be set again
which does not change the unmodifiable content.

Additionally it fixes the inconsitency that was prohibiting the support of
'CANFD-only' controller drivers.

Reported-by: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: linux-stable <stable@vger.kernel.org> 3.16+
---
 drivers/net/can/dev.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 141c2a4..b084cfd 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -696,11 +696,18 @@ int can_change_mtu(struct net_device *dev, int new_mtu)
 	/* allow change of MTU according to the CANFD ability of the device */
 	switch (new_mtu) {
 	case CAN_MTU:
+		/* take care of 'CANFD-only' controllers */
+		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
+		    (priv->ctrlmode & CAN_CTRLMODE_FD))
+			return -EINVAL;
+
 		priv->ctrlmode &= ~CAN_CTRLMODE_FD;
 		break;
 
 	case CANFD_MTU:
-		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD))
+		/* check for CANFD capability */
+		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
+		    !(priv->ctrlmode & CAN_CTRLMODE_FD))
 			return -EINVAL;
 
 		priv->ctrlmode |= CAN_CTRLMODE_FD;
@@ -819,10 +826,13 @@ static int can_changelink(struct net_device *dev,
 			return -EBUSY;
 		cm = nla_data(data[IFLA_CAN_CTRLMODE]);
 
-		/* check whether changed bits are allowed to be modified */
-		if (cm->mask & ~priv->ctrlmode_supported)
+		/* check whether provided bits are allowed to be passed */
+		if (cm->mask & ~(priv->ctrlmode_supported | priv->ctrlmode))
 			return -EOPNOTSUPP;
 
+		/* reduce to bits that are allowed to be modified */
+		cm->mask &= priv->ctrlmode_supported;
+
 		/* clear bits to be modified and copy the flag values */
 		priv->ctrlmode &= ~cm->mask;
 		priv->ctrlmode |= (cm->flags & cm->mask);
-- 
2.7.0

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

* Re: [RFC] [PATCH] can: fix handling of unmodifiable configuration options
  2016-03-08 17:13 [RFC] [PATCH] can: fix handling of unmodifiable configuration options Oliver Hartkopp
@ 2016-03-08 18:22 ` Oliver Hartkopp
  2016-03-09  9:27 ` Ramesh Shanmugasundaram
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2016-03-08 18:22 UTC (permalink / raw)
  To: linux-can; +Cc: ramesh.shanmugasundaram, linux-stable 3 . 16+



On 03/08/2016 06:13 PM, Oliver Hartkopp wrote:
> As described in 'can: m_can: tag current CAN FD controllers as non-ISO'
> (6cfda7fbebe) it is possible to define fixed configuration options by
> setting the according bit in 'ctrlmode' and clear it in 'ctrlmode_supported'.
> This leads to the incovenience that the fixed configuration can not be passed
> by netlink (ip tool) even when it has the correct value (e.g. non-ISO, FD).
> 
> This patch fixes that issue and allows fixed set bit values to be set again
> which does not change the unmodifiable content.
> 
> Additionally it fixes the inconsitency that was prohibiting the support of
> 'CANFD-only' controller drivers.
> 
> Reported-by: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> Cc: linux-stable <stable@vger.kernel.org> 3.16+
> ---
>  drivers/net/can/dev.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> index 141c2a4..b084cfd 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -696,11 +696,18 @@ int can_change_mtu(struct net_device *dev, int new_mtu)
>  	/* allow change of MTU according to the CANFD ability of the device */
>  	switch (new_mtu) {
>  	case CAN_MTU:
> +		/* take care of 'CANFD-only' controllers */
> +		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
> +		    (priv->ctrlmode & CAN_CTRLMODE_FD))
> +			return -EINVAL;
> +
>  		priv->ctrlmode &= ~CAN_CTRLMODE_FD;
>  		break;
>  
>  	case CANFD_MTU:
> -		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD))
> +		/* check for CANFD capability */
> +		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
> +		    !(priv->ctrlmode & CAN_CTRLMODE_FD))
>  			return -EINVAL;
>  
>  		priv->ctrlmode |= CAN_CTRLMODE_FD;
> @@ -819,10 +826,13 @@ static int can_changelink(struct net_device *dev,
>  			return -EBUSY;
>  		cm = nla_data(data[IFLA_CAN_CTRLMODE]);
>  
> -		/* check whether changed bits are allowed to be modified */
> -		if (cm->mask & ~priv->ctrlmode_supported)
> +		/* check whether provided bits are allowed to be passed */
> +		if (cm->mask & ~(priv->ctrlmode_supported | priv->ctrlmode))
>  			return -EOPNOTSUPP;
>  
> +		/* reduce to bits that are allowed to be modified */
> +		cm->mask &= priv->ctrlmode_supported;
> +

I just realized that I'm updating a provided netlink attribute here.
Does anyone know, whether this is feasible OR if I need to spend an extra
variable to perform the '&=' operation?

Are netlink attributes to be treated as constants?

Thanks,
Oliver

>  		/* clear bits to be modified and copy the flag values */
>  		priv->ctrlmode &= ~cm->mask;
>  		priv->ctrlmode |= (cm->flags & cm->mask);
> 

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

* RE: [RFC] [PATCH] can: fix handling of unmodifiable configuration options
  2016-03-08 17:13 [RFC] [PATCH] can: fix handling of unmodifiable configuration options Oliver Hartkopp
  2016-03-08 18:22 ` Oliver Hartkopp
@ 2016-03-09  9:27 ` Ramesh Shanmugasundaram
  2016-03-09 14:28   ` Oliver Hartkopp
  1 sibling, 1 reply; 4+ messages in thread
From: Ramesh Shanmugasundaram @ 2016-03-09  9:27 UTC (permalink / raw)
  To: Oliver Hartkopp, linux-can@vger.kernel.org; +Cc: linux-stable 3 . 16+

Hi Oliver,

Thanks for the patch.

> -----Original Message-----
> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
> Sent: 08 March 2016 17:14
> To: linux-can@vger.kernel.org
> Cc: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>;
> Oliver Hartkopp <socketcan@hartkopp.net>; linux-stable 3 . 16+
> <stable@vger.kernel.org>
> Subject: [RFC] [PATCH] can: fix handling of unmodifiable configuration
> options
> 
> As described in 'can: m_can: tag current CAN FD controllers as non-ISO'
> (6cfda7fbebe) it is possible to define fixed configuration options by
> setting the according bit in 'ctrlmode' and clear it in
> 'ctrlmode_supported'.

Shouldn't we document this? A comment to these variable definitions perhaps?

> This leads to the incovenience that the fixed configuration can not be
> passed by netlink (ip tool) even when it has the correct value (e.g. non-
> ISO, FD).
> 
> This patch fixes that issue and allows fixed set bit values to be set
> again which does not change the unmodifiable content.
> 
> Additionally it fixes the inconsitency that was prohibiting the support of
> 'CANFD-only' controller drivers.
> 
> Reported-by: Ramesh Shanmugasundaram
> <ramesh.shanmugasundaram@bp.renesas.com>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> Cc: linux-stable <stable@vger.kernel.org> 3.16+
> ---
>  drivers/net/can/dev.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index
> 141c2a4..b084cfd 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -696,11 +696,18 @@ int can_change_mtu(struct net_device *dev, int
> new_mtu)
>  	/* allow change of MTU according to the CANFD ability of the device
> */
>  	switch (new_mtu) {
>  	case CAN_MTU:
> +		/* take care of 'CANFD-only' controllers */
> +		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
> +		    (priv->ctrlmode & CAN_CTRLMODE_FD))
> +			return -EINVAL;
> +
>  		priv->ctrlmode &= ~CAN_CTRLMODE_FD;
>  		break;
> 
>  	case CANFD_MTU:
> -		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD))
> +		/* check for CANFD capability */
> +		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
> +		    !(priv->ctrlmode & CAN_CTRLMODE_FD))
>  			return -EINVAL;
> 
>  		priv->ctrlmode |= CAN_CTRLMODE_FD;
> @@ -819,10 +826,13 @@ static int can_changelink(struct net_device *dev,
>  			return -EBUSY;
>  		cm = nla_data(data[IFLA_CAN_CTRLMODE]);
> 
> -		/* check whether changed bits are allowed to be modified */
> -		if (cm->mask & ~priv->ctrlmode_supported)
> +		/* check whether provided bits are allowed to be passed */
> +		if (cm->mask & ~(priv->ctrlmode_supported | priv->ctrlmode))
>  			return -EOPNOTSUPP;

I think we need to separate this check into two. Otherwise, it will still return success for "fd off" config even though the configuration is not really applied.

> 
> +		/* reduce to bits that are allowed to be modified */
> +		cm->mask &= priv->ctrlmode_supported;

If we separate the above check, I think we don't have to do this.

Thanks,
Ramesh

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

* Re: [RFC] [PATCH] can: fix handling of unmodifiable configuration options
  2016-03-09  9:27 ` Ramesh Shanmugasundaram
@ 2016-03-09 14:28   ` Oliver Hartkopp
  0 siblings, 0 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2016-03-09 14:28 UTC (permalink / raw)
  To: Ramesh Shanmugasundaram, linux-can@vger.kernel.org



On 03/09/2016 10:27 AM, Ramesh Shanmugasundaram wrote:
> Hi Oliver,
> 
> Thanks for the patch.
> 
>> -----Original Message-----
>> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
>> Sent: 08 March 2016 17:14
>> To: linux-can@vger.kernel.org
>> Cc: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>;
>> Oliver Hartkopp <socketcan@hartkopp.net>; linux-stable 3 . 16+
>> <stable@vger.kernel.org>
>> Subject: [RFC] [PATCH] can: fix handling of unmodifiable configuration
>> options
>>
>> As described in 'can: m_can: tag current CAN FD controllers as non-ISO'
>> (6cfda7fbebe) it is possible to define fixed configuration options by
>> setting the according bit in 'ctrlmode' and clear it in
>> 'ctrlmode_supported'.
> 
> Shouldn't we document this? A comment to these variable definitions perhaps?

Yes. Good idea. Will do this in the updated patch.

> 
>> This leads to the incovenience that the fixed configuration can not be
>> passed by netlink (ip tool) even when it has the correct value (e.g. non-
>> ISO, FD).
>>
>> This patch fixes that issue and allows fixed set bit values to be set
>> again which does not change the unmodifiable content.
>>
>> Additionally it fixes the inconsitency that was prohibiting the support of
>> 'CANFD-only' controller drivers.
>>
>> Reported-by: Ramesh Shanmugasundaram
>> <ramesh.shanmugasundaram@bp.renesas.com>
>> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
>> Cc: linux-stable <stable@vger.kernel.org> 3.16+
>> ---
>>  drivers/net/can/dev.c | 16 +++++++++++++---
>>  1 file changed, 13 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index
>> 141c2a4..b084cfd 100644
>> --- a/drivers/net/can/dev.c
>> +++ b/drivers/net/can/dev.c
>> @@ -696,11 +696,18 @@ int can_change_mtu(struct net_device *dev, int
>> new_mtu)
>>  	/* allow change of MTU according to the CANFD ability of the device
>> */
>>  	switch (new_mtu) {
>>  	case CAN_MTU:
>> +		/* take care of 'CANFD-only' controllers */
>> +		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
>> +		    (priv->ctrlmode & CAN_CTRLMODE_FD))
>> +			return -EINVAL;
>> +
>>  		priv->ctrlmode &= ~CAN_CTRLMODE_FD;
>>  		break;
>>
>>  	case CANFD_MTU:
>> -		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD))
>> +		/* check for CANFD capability */
>> +		if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) &&
>> +		    !(priv->ctrlmode & CAN_CTRLMODE_FD))
>>  			return -EINVAL;
>>
>>  		priv->ctrlmode |= CAN_CTRLMODE_FD;
>> @@ -819,10 +826,13 @@ static int can_changelink(struct net_device *dev,
>>  			return -EBUSY;
>>  		cm = nla_data(data[IFLA_CAN_CTRLMODE]);
>>
>> -		/* check whether changed bits are allowed to be modified */
>> -		if (cm->mask & ~priv->ctrlmode_supported)
>> +		/* check whether provided bits are allowed to be passed */
>> +		if (cm->mask & ~(priv->ctrlmode_supported | priv->ctrlmode))
>>  			return -EOPNOTSUPP;
> 
> I think we need to separate this check into two. Otherwise, it will still return success for "fd off" config even though the configuration is not really applied.

Yes. I'll re-think this check. Your "fd off" use-case is a good case to take
care about.

> 
>>
>> +		/* reduce to bits that are allowed to be modified */
>> +		cm->mask &= priv->ctrlmode_supported;
> 
> If we separate the above check, I think we don't have to do this.

At least I'll make it a separate variable, so that the netlink data remains
read-only.

Thanks,
Oliver


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

end of thread, other threads:[~2016-03-09 14:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-08 17:13 [RFC] [PATCH] can: fix handling of unmodifiable configuration options Oliver Hartkopp
2016-03-08 18:22 ` Oliver Hartkopp
2016-03-09  9:27 ` Ramesh Shanmugasundaram
2016-03-09 14:28   ` Oliver Hartkopp

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