On Tue, Aug 20, 2019 at 08:36:50PM +0800, zhangfei wrote:We are thinking transfer structure will be more flexible.
Hi, GregWhat? Why do you need a structure? A pointer to the name and the ops
On 2019/8/19 äå6:24, Greg Kroah-Hartman wrote:
OK, understand now, thanks for your patience.crypto is not a subsystem to ever try to emulate :)I think you mean uacce structure here.+static int uacce_create_chrdev(struct uacce *uacce)Shouldn't this function create the memory needed for this structure?
+{
+ int ret;
+
+ ret = idr_alloc(&uacce_idr, uacce, 0, 0, GFP_KERNEL);
+ if (ret < 0)
+ return ret;
+
You are relying ont he caller to do it for you, why?
Yes, currently we count on caller to prepare uacce structure and call
uacce_register(uacce).
We still think this method is simpler, prepare uacce, register uacce.
And there are other system using the same method, like crypto
(crypto_register_acomp), nand, etc.
You are creating a structure with a lifetime that you control, don't
have someone else create your memory, that's almost never what you want
to do. Most all driver subsystems create their own memory chunks for
what they need to do, it's a much better pattern.
Especially when you get into pointer lifetime issues...
will use this instead.
struct uacce_interface {
ÂÂÂÂÂÂÂ char name[32];
ÂÂÂÂÂÂÂ unsigned int flags;
ÂÂÂÂÂÂÂ struct uacce_ops *ops;
};
struct uacce *uacce_register(struct device *dev, struct uacce_interface
*interface);
should be all that is needed, right?
And 'dev' here is a pointer to the parent, right? Might want to makeYes, 'dev' is parent, will change to 'pdev', thanks.
that explicit in the name of the variable :)
You should NEVER be matching on a parent. If so, your use of the driverSuppose you mean the funcs: device_match_name,It is in linux-next, look there...Sorry, do not find this function.+There should be in-kernel functions for this now, no need for you to
+static int uacce_dev_match(struct device *dev, void *data)
+{
+ if (dev->parent == data)
+ return -EBUSY;
roll your own.
Only find class_find_device, which still require match.
device_match_of_node,device_match_devt etc.
Here we need dev->parent, there still no such func.
model is wrong :)
Remind me to really review the use of the driver core code in your next
submission of this series please, I think it needs it.