Re: [PATCH v3 12/14] intel_gna: add a 'misc' device

From: Maciej Kwapulinski
Date: Thu May 13 2021 - 13:09:14 EST



Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> writes:

> On Thu, May 13, 2021 at 01:00:38PM +0200, Maciej Kwapulinski wrote:
>> The new 'misc' device is the node for applications in user space to
>> interact with the driver.
>>
>> Signed-off-by: Maciej Kwapulinski <maciej.kwapulinski@xxxxxxxxxxxxxxx>
>> Tested-by: Savo Novakovic <savox.novakovic@xxxxxxxxx>
>> ---
>> drivers/misc/intel/gna/device.c | 52 +++++++++++++++++++++++++++++++--
>> drivers/misc/intel/gna/device.h | 11 +++----
>> 2 files changed, 55 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/misc/intel/gna/device.c b/drivers/misc/intel/gna/device.c
>> index 0e31b8c6bb70..1e6345a8325b 100644
>> --- a/drivers/misc/intel/gna/device.c
>> +++ b/drivers/misc/intel/gna/device.c
>> @@ -20,6 +20,18 @@ module_param(recovery_timeout, int, 0644);
>> MODULE_PARM_DESC(recovery_timeout, "Recovery timeout in seconds");
>> #endif
>>
>> +struct file;
>> +
>> +static int gna_open(struct inode *inode, struct file *f)
>> +{
>> + return -EPERM;
>> +}
>
> That sucks, why have an open that does nothing but fail?

next patch provides complete implementation of gna_open(), here it's
just a protection if someone would incidentally run gna in the middle of patch series

>
>> +
>> +static const struct file_operations gna_file_ops = {
>> + .owner = THIS_MODULE,
>> + .open = gna_open,
>> +};
>> +
>> static void gna_devm_idr_destroy(void *data)
>> {
>> struct idr *idr = data;
>> @@ -27,6 +39,36 @@ static void gna_devm_idr_destroy(void *data)
>> idr_destroy(idr);
>> }
>>
>> +static void gna_devm_deregister_misc_dev(void *data)
>
> Why is this a void *?

it goes to devm_add_action() api.

>
> This isn't windows, use real pointer types everywhere in the kernel
> please.
>
>> +{
>> + struct miscdevice *misc = data;
>> +
>> + misc_deregister(misc);
>> +}
>> +
>> +static int gna_devm_register_misc_dev(struct device *parent, struct miscdevice *misc)
>> +{
>> + int ret;
>> +
>> + ret = misc_register(misc);
>> + if (ret) {
>> + dev_err(parent, "misc device %s registering failed. errcode: %d\n",
>> + misc->name, ret);
>> + gna_devm_deregister_misc_dev(misc);
>> + } else {
>> + dev_dbg(parent, "device: %s registered\n",
>> + misc->name);
>
> You have loads of debugging in this driver still, is it really needed?
>
>> + }
>> +
>> + ret = devm_add_action(parent, gna_devm_deregister_misc_dev, misc);
>
> Why do you need this?

I'd like to avoid having gna_probe's fail path at all.

>
>
> thanks,
>
> greg k-h