Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4000016ybz; Tue, 28 Apr 2020 04:07:45 -0700 (PDT) X-Google-Smtp-Source: APiQypLEap4A6Yjj1wVFn6oF3KVtwYO5EvNzjY5w0M8BQwN5H1IN++t5EC5hIns/siU5y/pevK9N X-Received: by 2002:a17:906:4e46:: with SMTP id g6mr23477803ejw.36.1588072065213; Tue, 28 Apr 2020 04:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588072065; cv=none; d=google.com; s=arc-20160816; b=z0B1iECH+E37QgqgZn3ioLIS0HyGZNS3VVy/CbgQ/pQ6DubgXsUxQZlLdTLlh28MZt zTyslv0g4X6nxgNgSKi6RGAeLnZi8A1YBq9ibNjg2CSMBPBe+6fv2KY+RdJrBz+P2x2K oxmaQefscu84I3FZjT/+7OwDgd1sA0c2phDith2Hxx32WuwAXPNAzHyHR9Az4XmFNR+o pKk/VI+At3RXOGQWxowJmtJCp0DmAoZBn894DsSCqKhJpGGnZzapoRQl176dsgRm+r0e E4KuJMTf8PceI67b+iBQ2mrkNigIHpI0JyGyT23jHQDvZi2IbGQFRcMDw+6wlXiwmhqu A1xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HkaLmzHsHgw5ZH2LcpaCC5Qfg5RzNvvwd9M/GbXj0jg=; b=LmoDYOBEN9obAZ2MvydPJ1Hb+dbVtZ0YZWA5JnGsUSbWlcbUEwClz4ut5pSe+fM2x9 i4OE99ajGVo+bQiyqd5+fEFVAJLg7Lx9bKVqPkh/M7afu2cUU3eJx86mJPfoG97IXBov JxSmZTtv3W/ZtYIOw6oKtFyIiAHAL+H4n7BVmUP/0DKze4HD8bXtOCUNa8DuNB1deWQX pJeMQWOkXSNtw1wEsT0P/k90Wn5nStA9Wf6wMnlMR4K/pXge5X37mg0Di67H838G6WSd pdJFWdZR4OvMyJR9Irg3Kvr7rl20OURP5UlpONz5mTAlj0PvnP9KIB14dhxROx5adpGZ x4Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qqAC43x8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si1487542edu.188.2020.04.28.04.07.21; Tue, 28 Apr 2020 04:07:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qqAC43x8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726482AbgD1LDw (ORCPT + 99 others); Tue, 28 Apr 2020 07:03:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:58262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726364AbgD1LDv (ORCPT ); Tue, 28 Apr 2020 07:03:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E875420661; Tue, 28 Apr 2020 11:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588071830; bh=z+/W1GSQCnaDa8dvtTYWSzpbMQuuEer9i0Mzts4YpcI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qqAC43x89Xm1ntiVsqdQTKd1kN/p5WhF22eBKmRMvGvOyJtvk6dpSn2Q8CNyxV0og d1Z+V6MUaEeoqiwMyt3q7+4aeu27SjSYfFfL7VUCVXZ0O2e0DRiDYgHkGHYbXVQqR6 bC+Vg6qafL0gzjvvZwggIuYm/wOGtoWWpQHiYnVU= Date: Tue, 28 Apr 2020 13:03:47 +0200 From: Greg KH To: vladimir.stankovic@displaylink.com Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, mausb-host-devel@displaylink.com Subject: Re: [PATCH v5 1/8] usb: Add MA-USB Host kernel module Message-ID: <20200428110347.GA1145239@kroah.com> References: <20200327152614.26833-1-vladimir.stankovic@displaylink.com> <20200425091954.1610-1-vladimir.stankovic@displaylink.com> <20200425091954.1610-2-vladimir.stankovic@displaylink.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200425091954.1610-2-vladimir.stankovic@displaylink.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 25, 2020 at 11:19:47AM +0200, vladimir.stankovic@displaylink.com wrote: > Added utility macros, kernel device creation and cleanup, functions for > handling log formatting and a placeholder module for MA-USB Host device > driver. > > Signed-off-by: Vladimir Stankovic > --- > MAINTAINERS | 7 +++ > drivers/usb/Kconfig | 2 + > drivers/usb/Makefile | 2 + > drivers/usb/mausb_host/Kconfig | 15 +++++ > drivers/usb/mausb_host/Makefile | 12 ++++ > drivers/usb/mausb_host/mausb_core.c | 90 +++++++++++++++++++++++++++++ > drivers/usb/mausb_host/utils.c | 85 +++++++++++++++++++++++++++ > drivers/usb/mausb_host/utils.h | 40 +++++++++++++ > 8 files changed, 253 insertions(+) > create mode 100644 drivers/usb/mausb_host/Kconfig > create mode 100644 drivers/usb/mausb_host/Makefile > create mode 100644 drivers/usb/mausb_host/mausb_core.c > create mode 100644 drivers/usb/mausb_host/utils.c > create mode 100644 drivers/usb/mausb_host/utils.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 453fe0713e68..8b63b246ba67 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -10352,6 +10352,13 @@ W: https://linuxtv.org > T: git git://linuxtv.org/media_tree.git > F: drivers/media/radio/radio-maxiradio* > > +MEDIA AGNOSTIC (MA) USB HOST DRIVER > +M: Vladimir Stankovic > +L: mausb-host-devel@displaylink.com > +W: https://www.displaylink.com > +S: Maintained > +F: drivers/usb/mausb_host/* > + > MCAN MMIO DEVICE DRIVER > M: Dan Murphy > M: Sriram Dash > diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig > index 275568abc670..4e92f1fa0fa5 100644 > --- a/drivers/usb/Kconfig > +++ b/drivers/usb/Kconfig > @@ -164,6 +164,8 @@ source "drivers/usb/misc/Kconfig" > > source "drivers/usb/atm/Kconfig" > > +source "drivers/usb/mausb_host/Kconfig" > + > endif # USB > > source "drivers/usb/phy/Kconfig" > diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile > index 1c1c1d659394..22d1998db0e2 100644 > --- a/drivers/usb/Makefile > +++ b/drivers/usb/Makefile > @@ -66,3 +66,5 @@ obj-$(CONFIG_USBIP_CORE) += usbip/ > obj-$(CONFIG_TYPEC) += typec/ > > obj-$(CONFIG_USB_ROLE_SWITCH) += roles/ > + > +obj-$(CONFIG_HOST_MAUSB) += mausb_host/ > diff --git a/drivers/usb/mausb_host/Kconfig b/drivers/usb/mausb_host/Kconfig > new file mode 100644 > index 000000000000..a8363e7e8f97 > --- /dev/null > +++ b/drivers/usb/mausb_host/Kconfig > @@ -0,0 +1,15 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Kernel configuration file for MA-USB Host driver. > +# > +# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. > +# > + > +config HOST_MAUSB > + tristate "Media Agnostic (MA) USB Host Driver" > + depends on USB=y Why can't USB=m? > + help > + This is a Media Agnostic (MA) USB Host driver which enables host > + communication via MA USB protocol stack. > + > + If this driver is compiled as a module, it will be named mausb_host. And why isn't this all in drivers/usb/host/ ? Why a separate directory? If you really need your own directory, why not drivers/usb/host/mausb/ ? > diff --git a/drivers/usb/mausb_host/Makefile b/drivers/usb/mausb_host/Makefile > new file mode 100644 > index 000000000000..2e353fa0958b > --- /dev/null > +++ b/drivers/usb/mausb_host/Makefile > @@ -0,0 +1,12 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Makefile for DisplayLink MA-USB Host driver. > +# > +# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. > +# > + > +obj-$(CONFIG_HOST_MAUSB) += mausb_host.o > +mausb_host-y := mausb_core.o > +mausb_host-y += utils.o > + > +ccflags-y += -I$(srctree)/$(src) Ick, really? Why? You should not need this. > diff --git a/drivers/usb/mausb_host/mausb_core.c b/drivers/usb/mausb_host/mausb_core.c > new file mode 100644 > index 000000000000..8638dd0a4856 > --- /dev/null > +++ b/drivers/usb/mausb_host/mausb_core.c > @@ -0,0 +1,90 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. > + */ > +#include > +#include Why do you need these two .h files for this file at this time? > +#include > +#include > +#include > +#include > +#include You have no module parameters here, why do you need this? > +#include Why do you need this? > + > +#include "utils.h" > + > +MODULE_LICENSE("GPL"); > +MODULE_AUTHOR("DisplayLink (UK) Ltd."); > +MODULE_VERSION(MAUSB_DRIVER_VERSION); > + > +static int mausb_client_connect(const char *value, > + const struct kernel_param *kp) > +{ > + mausb_pr_info("Version=%s", MAUSB_DRIVER_VERSION); No custom driver "printk" macros please. We have been stomping them out for years. Just use dev_*() instead. And a driver version means nothing when it is in the kernel itself, please just remove. > + > + return 0; > +} > + > +static int mausb_client_disconnect(const char *value, > + const struct kernel_param *kp) > +{ > + mausb_pr_info("Version=%s", MAUSB_DRIVER_VERSION); Also, why info? This is just fun debugging stuff, don't do that, that is what ftrace is for. If you are trying to provide stubs to later fill in, that's fine, but don't clutter it up with this type of stuff please. > +int mausb_create_dev(void) > +{ > + int device_created = 0; > + int status = alloc_chrdev_region(&mausb_major_kernel, 0, 1, > + MAUSB_KERNEL_DEV_NAME "_proc"); Why does a USB host driver need a char dev node? > + if (status) > + goto cleanup; > + > + mausb_kernel_class = class_create(THIS_MODULE, > + MAUSB_KERNEL_DEV_NAME "_sys"); Why do you need your own class that has a different name from your device node? None of that should be needed at all here, right? > + if (!mausb_kernel_class) { > + status = -ENOMEM; > + goto cleanup; > + } > + > + if (!device_create(mausb_kernel_class, NULL, mausb_major_kernel, NULL, > + MAUSB_KERNEL_DEV_NAME "_dev")) { > + status = -ENOMEM; > + goto cleanup; > + } > + device_created = 1; You set this and never touch it again :( Oh wait, you pass it into a cleanup function later, which isn't really needed anyway. > + cdev_init(&mausb_kernel_dev, &mausb_file_ops); > + status = cdev_add(&mausb_kernel_dev, mausb_major_kernel, 1); one device node? If you REALLY need it, just use a misc device, but we need a ton of documentation here as to what you are doing with this, and why it is needed, because as-is, I have no idea just looking at this patch :( > + if (status) > + goto cleanup; > + return 0; > +cleanup: > + mausb_cleanup_dev(device_created); > + return status; > +} > + > +void mausb_cleanup_dev(int device_created) > +{ > + if (device_created) { So this isn't a global variable?? That really isn't needed, please don't. > + device_destroy(mausb_kernel_class, mausb_major_kernel); > + cdev_del(&mausb_kernel_dev); > + } > + > + if (mausb_kernel_class) > + class_destroy(mausb_kernel_class); > + > + unregister_chrdev_region(mausb_major_kernel, 1); > +} > diff --git a/drivers/usb/mausb_host/utils.h b/drivers/usb/mausb_host/utils.h > new file mode 100644 > index 000000000000..9adf4122e64d > --- /dev/null > +++ b/drivers/usb/mausb_host/utils.h > @@ -0,0 +1,40 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. > + */ > +#ifndef __MAUSB_UTILS_H__ > +#define __MAUSB_UTILS_H__ > + > +#if defined(MAUSB_NO_LOGS) > +#define mausb_pr_logs(...) > +#else > +#include > +#include > +#define mausb_pr_logs(level_str, level, log, ...)\ > + pr_##level_str("MAUSB " #level " [%x:%x] [%s] " log "\n",\ > + current->pid, current->tgid, __func__, ##__VA_ARGS__) > +#endif /* MAUSB_NO_LOGS */ > + > +#define mausb_pr_alert(...) mausb_pr_logs(alert, 1, ##__VA_ARGS__) > + > +#define mausb_pr_err(...) mausb_pr_logs(err, 2, ##__VA_ARGS__) > + > +#define mausb_pr_warn(...) mausb_pr_logs(warn, 3, ##__VA_ARGS__) > + > +#define mausb_pr_info(...) mausb_pr_logs(info, 4, ##__VA_ARGS__) > + > +#if defined(MAUSB_LOG_VERBOSE) > + #define mausb_pr_debug(...) mausb_pr_logs(debug, 5, ##__VA_ARGS__) > +#else > + #define mausb_pr_debug(...) > +#endif /* defined(MAUSB_LOG_VERBOSE) */ Again, drop all of this, and use the build-in kernel functions, there's nothing special about this one tiny driver to override uniformity. > + > +#define MAUSB_STRINGIFY2(x) #x > +#define MAUSB_STRINGIFY(x) MAUSB_STRINGIFY2(x) Ick, why??? > + > +#define MAUSB_DRIVER_VERSION MAUSB_STRINGIFY(1.3.0.0.6f5beb53) That's funny. And pointless :) > + > +int mausb_create_dev(void); > +void mausb_cleanup_dev(int device_created); No need for that parameter. thanks, greg k-h