lkml.org 
[lkml]   [2019]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v11 1/5] can: m_can: Create a m_can platform framework
Date
On 5/8/19 9:54 PM, Dan Murphy wrote:
>>> -/* m_can private data structure */
>>> -struct m_can_priv {
>>> - struct can_priv can; /* must be the first member */
>>> - struct napi_struct napi;
>>> - struct net_device *dev;
>>> - struct device *device;
>>> - struct clk *hclk;
>>> - struct clk *cclk;
>>> - void __iomem *base;
>>> - u32 irqstatus;
>>> - int version;
>>> -
>>> - /* message ram configuration */
>>> - void __iomem *mram_base;
>>> - struct mram_cfg mcfg[MRAM_CFG_NUM];
>>> -};
>>> +static u32 m_can_read(struct m_can_priv *priv, enum m_can_reg reg)
>>> +{
>>> + if (priv->ops->read_reg)
>>> + return priv->ops->read_reg(priv, reg);
>>> + else
>>> + return -EINVAL;
>>> +}
>>
>> How do you plan to check the return value here?
>> What's the difference between a register value of 0xffffffe9 and
>> returning -EINVAL?
>
> Good point. I could just inline this and return whatever is sent
> from the callback and as you said allow a backtrace to happen if
> read_reg is invalid.

ACK.
A minimal function will look like this:

static inline u32 m_can_read(struct m_can_priv *priv, enum m_can_reg reg)
{
return priv->ops->read_reg(priv, reg);
}

And of ops or read_reg is NULL, the kernel will access a NULL pointer
that would then generate a backtrace.

>>> -static inline u32 m_can_read(const struct m_can_priv *priv, enum m_can_reg reg)
>>> +static int m_can_write(struct m_can_priv *priv, enum m_can_reg reg, u32 val)
>>> {
>>> - return readl(priv->base + reg);
>>> + if (priv->ops->write_reg)
>>> + return priv->ops->write_reg(priv, reg, val);
>>> + else
>>> + return -EINVAL;
>>> }
>>
>> I don't see anyone checking the return value. Better just dereference
>> the pointer and the kernel will produce a nice backtrace.
>>
>> Same should be done for all read and write variants.
>>
>
> I will need to go through this and see if there is any caller checking the return. But
> I think you are correct. If thats true I will just change this to a void, inline the function
> and allow a backtrace if the callback is null

ok

regards,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |

[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2019-05-09 08:39    [W:0.040 / U:3.488 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site