+
+struct sid_priv {
+ void __iomem *sid_base;
+};
+
+struct sid_priv *p;
What's the point of having a structure here? And why putting a global
value, !static, with a generic name, while you could have an
instance-specific one?
So what happens if you have two of these devices? Maybe you want to check
whether p_sid_reg_base is already set?
It goes kaboom. Again, i had no idea naturally. I think what you meant was, if you unbind and p_sid_reg_base points to 'somewhere' and we just randomly read bytes. I added p_sid_reg_base to the guard above to at least check if it's not NULL.+ if (likely((SID_SIZE))) {
+ sid_key = ioread32be(p_sid_reg_base + round_down(offset, 4));
+ sid_key >>= (offset % 4) * 8;
+ ret = sid_key & 0xff;
+ }
What happens if you unbind the device in sysfs and then try and use
this function?
Yeah, that made even more sense to the above thing and added it. When we unbind or unload the driver, we point to NULL and a) can check for it above and don't have nasty things dangling around. I think it was save to assume, that when the driver is unloaded/unbound, the devm_set_data() private data gets cleaned and the pointer set to NULL? I think that's what Maxime/Emilio said, by using the devm stuff, those should get cleaned up properly.+static int sunxi_sid_remove(struct platform_device *pdev)
+{
+ device_remove_bin_file(&pdev->dev, &sid_bin_attr);
+ dev_info(&pdev->dev, "Sunxi SID driver unloaded successfully.\n");
Maybe you want to set p_sid_reg_base to NULL here?
Even that hint didn't trigger me as to why this could cause problems. Userspace guy here, every driver has its own memory space right? So I've added a guard that we only load this driver once and only if p_sid_reg_base is NULL.+ platform_set_drvdata(pdev, sid_reg_base);
+ p_sid_reg_base = sid_reg_base;
So what happens if you have two of these devices? Maybe you want to check
whether p_sid_reg_base is already set?
Don't we do that already though? I made the string more informative by adding version information, but yeah I see tons of 'all is ok' rolling by, isn't that a good thing? Isn't that only printed if we actually have a SID onboard, so the user knows 'sid is available'. I know I often scroll through dmesg to see if things got brought up nicely.+ dev_info(dev, "Sunxi SID driver loaded successfully.\n");
Do we really need to report that the driver "loaded successfully" ?
Do we need lots of lines in the kernel log telling us simply that
random driver X was built into the kernel or the module was loaded?
On 06-06-13 21:16, Andy Shevchenko wrote:While this is a really small function, I guess if that's the normal course of things; why not.+ if (likely((SID_SIZE))) {Extra braces.
Use antipattern here.
On 06-06-13 21:16, Andy Shevchenko wrote:With ret removed, I assume having return (u8)sid_key; is okay? Does that typecast only return the last byte? Or do we still want & 0xff in the return added for clarity?+ ret = sid_key & 0xff;No need to do & 0xff, since return type is byte.
That's a good rule to group variables with, I should have known. Done.+static int __init sunxi_sid_probe(struct platform_device *pdev)
+{
+ int entropy[SID_SIZE], i, ret;
Usually ret variable is located at the end of definition block.
Moreover, there is no relationship between those three. It means one
line per variable.
On 06-06-13 21:16, Andy Shevchenko wrote:I would have thought that 'dev' would that it would be the same and valid,+ dev = &pdev->dev;Please, be consistent, somewhere you still use &pdev->dev.
I recomend to use &pdev->dev everywhere in probe(), since we don't
know if the device will be probed successfully.