Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp257328imm; Mon, 4 Jun 2018 17:07:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJSy/JcYOWOON+t6T300wBRR9/FrOBSYWCvEnhQM4876/oUylJuU+bp0bm7v+h1DSzU/rbZ X-Received: by 2002:aa7:8084:: with SMTP id v4-v6mr23227276pff.105.1528157261960; Mon, 04 Jun 2018 17:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528157261; cv=none; d=google.com; s=arc-20160816; b=0SgY4j0Zv0n1ryk97a9t+mlaD86GfCRH2cdoXLXtnQmKamCgKI9nS6Ff5w/30r8jA5 Y6SMEyyms0ouExu75lkfG9hjDFhmVbRsBv94vhfgsgPb6MX+DuwDNpy1vNFvgVelb1yo MKIfnYiXdeKCkDIe1Hn15VXsJ0bPmZt3IbeX8W5V1uaCJ1jmxKi2YuMdu1fZG0HlImZP nky1870i4FTuaoinYSbWg2ChCCVGhF6ER3LfsW31DzNvzEatvGCcde4sWscAEeAdOvUZ pNvAi9mpXZncCKH1c78OGAqPeuNmpg3sxZ54V9wy4iNtH1BOCSUs/rcfYyNIiRPpFdis edqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=wqE0+tdyg4grlVJjULrXQqy7WNLKfIRpqT7szYXCdaw=; b=AdJBxzz1SEuN7/viyW/mcDVeChouAI4Ic0qX7WYUtoW6dzN67GNV/ucV0zyZPGxkaR t2U0O+yzEO5UrSEJ1+83QX1fmG6CBEIhXIY84xfE/k3ElwXjQOM07nNpEbUeDkA7nU0A Cwvc24ncluV65wbXnmh5e3QNhk4xm/qqnYzOfywe2rwO/gkV3oL3mGR8icmE4y9XqGqO xs0xYWjlujcQLUX87MEWUtxUxkjeRyrViF6k5k9E7fCmypejz6GDgNgE2Cg64IBpQaZb PvlCMKw34orMQfO+zLnt+GwccmO+R36/j36bFwq0Q1QRlyN19Uo6Bj+IvAa5dHqwfs0a sKug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Naq6MFr0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o26-v6si8920144pfe.44.2018.06.04.17.07.27; Mon, 04 Jun 2018 17:07:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Naq6MFr0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751247AbeFEAHE (ORCPT + 99 others); Mon, 4 Jun 2018 20:07:04 -0400 Received: from mail-yb0-f193.google.com ([209.85.213.193]:40294 "EHLO mail-yb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbeFEAHD (ORCPT ); Mon, 4 Jun 2018 20:07:03 -0400 Received: by mail-yb0-f193.google.com with SMTP id v17-v6so165583ybe.7 for ; Mon, 04 Jun 2018 17:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wqE0+tdyg4grlVJjULrXQqy7WNLKfIRpqT7szYXCdaw=; b=Naq6MFr0891WNuERWtKZLhCFY6sxaVxd5/SOXOV/TqLQw/sSHvvnvVLK5vYJGHU3Kr irCnabwxTfWnGY6KFEPv953Q/u5WZpOFOIOO17PDm6F9CheJDGtd345/N0hhX+qjG/zf 6ppEKEShWItB5ylSw90A0Ju6p6bHI/tKa049g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wqE0+tdyg4grlVJjULrXQqy7WNLKfIRpqT7szYXCdaw=; b=StwGGOnNwxdAaF9I+Kew6GLX+12gucJC/bre7ccBkoOutITJvsbk08cQjV93gGx+kZ mptHgO2JKHCn/84AdmqGtoxUtmQ2hc4CUjeqtb4S4FJ7O2//6UuycRAXKCFhFjAkY3iK m05xgJDpo0TFwKdU3EZWivyl0ZOwMNDZM7Hf46/x5sj9Y3C9tNcXW/fLsPZJNmgb75yT Mh8MZgpncEMgF7bfAzLHqgCNPQXFo1bH0SmcptIHuHH7cAGVwQVtzB03dMFkA0CYb60F HHva+ooAnxjYe6e35QTNbETZ5mQuANYVK/U76H0QKTPdHKfnoO1kWBJiW8lDSCaI2rAk RkIw== X-Gm-Message-State: ALKqPwf/t5owOMWjAuxQJxRW/hzxgf6+HgJg69rNFurJmpSo7ssXAxu/ bId4rSSqqwiNDbIABwO9P03U/5lN60ue/3HnJTBZqA== X-Received: by 2002:a25:5607:: with SMTP id k7-v6mr12381537ybb.475.1528157222031; Mon, 04 Jun 2018 17:07:02 -0700 (PDT) MIME-Version: 1.0 References: <20180604202235.73679-1-egranata@google.com> In-Reply-To: <20180604202235.73679-1-egranata@google.com> From: Gwendal Grignou Date: Mon, 4 Jun 2018 17:06:50 -0700 Message-ID: Subject: Re: [PATCH] Cleanup dependency chain for cros_ec modules To: Enrico Granata Cc: Linux Kernel , egranata@chromium.org, Benson Leung , Olof Johansson , Lee Jones Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 4, 2018 at 1:22 PM Enrico Granata wrote: > > From: Enrico Granata > > If one builds the Chrome EC support as modules, there is no explicit > dependency chain amongst the several modules (LPC, CHARDEV, CORE, ...) > > This makes it possible - for instance - to rmmod cros_ec_core, even though > cros_ec_dev actively uses it for data transport to the EC chip. > > This commit makes two changes in an attempt to address this: > a) moves cros_ec_proto.c as part of the CORE module; this removes the > possibility of unloading cros_ec_core while cros_ec_dev is using it; > b) enables cros_ec_core to explicitly register a runtime dependency on > the kernel module that is using its cmd and pkt transfer functions > > Signed-off-by: Enrico Granata > --- > > drivers/mfd/Kconfig | 1 - > drivers/mfd/Makefile | 2 +- > drivers/mfd/cros_ec.c | 17 ++++++++++++++++- > .../{platform/chrome => mfd}/cros_ec_proto.c | 0 > drivers/platform/chrome/Kconfig | 5 ----- > drivers/platform/chrome/Makefile | 1 - > drivers/platform/chrome/cros_ec_lpc.c | 1 + > include/linux/mfd/cros_ec.h | 2 ++ > 8 files changed, 20 insertions(+), 9 deletions(-) > rename drivers/{platform/chrome => mfd}/cros_ec_proto.c (100%) > > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig > index b860eb5aa194..a8daa2072ae6 100644 > --- a/drivers/mfd/Kconfig > +++ b/drivers/mfd/Kconfig > @@ -194,7 +194,6 @@ config MFD_CROS_EC > tristate "ChromeOS Embedded Controller" > select MFD_CORE > select CHROME_PLATFORMS > - select CROS_EC_PROTO > depends on X86 || ARM || ARM64 || COMPILE_TEST > help > If you say Y here you get support for the ChromeOS Embedded > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > index d9d2cf0d32ef..20537bd27695 100644 > --- a/drivers/mfd/Makefile > +++ b/drivers/mfd/Makefile > @@ -12,7 +12,7 @@ obj-$(CONFIG_MFD_SM501) += sm501.o > obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o > obj-$(CONFIG_MFD_BCM590XX) += bcm590xx.o > obj-$(CONFIG_MFD_BD9571MWV) += bd9571mwv.o > -cros_ec_core-objs := cros_ec.o > +cros_ec_core-objs := cros_ec.o cros_ec_proto.o We try to get cros_ec_proto out of mfd directory, it is weird to compile something from drivers/platform/chrome/ in drivers/mfd. > cros_ec_core-$(CONFIG_ACPI) += cros_ec_acpi_gpe.o > obj-$(CONFIG_MFD_CROS_EC) += cros_ec_core.o > obj-$(CONFIG_MFD_CROS_EC_I2C) += cros_ec_i2c.o > diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c > index d61024141e2b..109e9cb1e289 100644 > --- a/drivers/mfd/cros_ec.c > +++ b/drivers/mfd/cros_ec.c > @@ -168,9 +168,21 @@ int cros_ec_register(struct cros_ec_device *ec_dev) > */ > err = cros_ec_sleep_event(ec_dev, 0); > if (err < 0) > - dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec", > + dev_dbg(dev, "Error %d clearing sleep event to ec", > err); Concatenate both line. > > + if (ec_dev->xfer_fcn_owner != NULL) { > + err = try_module_get(ec_dev->xfer_fcn_owner); > + if (err < 0) { > + dev_err(dev, "Error %d acquiring transfer module", err); > + return err; > + } > + dev_info(dev, "Transfer module %p get successfully", > + ec_dev->xfer_fcn_owner); > + } else { > + dev_warn(dev, "No transfer module registered"); > + } > + > dev_info(dev, "Chrome EC device registered\n"); > > cros_ec_acpi_install_gpe_handler(dev); > @@ -193,6 +205,9 @@ int cros_ec_remove(struct cros_ec_device *ec_dev) > if (ec_dev->irq) > free_irq(ec_dev->irq, ec_dev); > > + if (ec_dev->xfer_fcn_owner != NULL) > + module_put(ec_dev->xfer_fcn_owner); > + > return 0; > } > EXPORT_SYMBOL(cros_ec_remove); > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/mfd/cros_ec_proto.c > similarity index 100% > rename from drivers/platform/chrome/cros_ec_proto.c > rename to drivers/mfd/cros_ec_proto.c > diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig > index e728a96cabfd..a050c9e8b506 100644 > --- a/drivers/platform/chrome/Kconfig > +++ b/drivers/platform/chrome/Kconfig > @@ -65,11 +65,6 @@ config CROS_EC_LPC_MEC > If you have a ChromeOS Embedded Controller Microchip EC variant > choose Y here. > > -config CROS_EC_PROTO > - bool > - help > - ChromeOS EC communication protocol helpers. > - > config CROS_KBD_LED_BACKLIGHT > tristate "Backlight LED support for Chrome OS keyboards" > depends on LEDS_CLASS && ACPI > diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile > index ff3b369911f0..0b5e26ca9c96 100644 > --- a/drivers/platform/chrome/Makefile > +++ b/drivers/platform/chrome/Makefile > @@ -8,5 +8,4 @@ obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o > cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_reg.o > cros_ec_lpcs-$(CONFIG_CROS_EC_LPC_MEC) += cros_ec_lpc_mec.o > obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o > -obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o > obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o > diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c > index 3682e1539251..8f02b188bd3f 100644 > --- a/drivers/platform/chrome/cros_ec_lpc.c > +++ b/drivers/platform/chrome/cros_ec_lpc.c > @@ -282,6 +282,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) > ec_dev->phys_name = dev_name(dev); > ec_dev->cmd_xfer = cros_ec_cmd_xfer_lpc; > ec_dev->pkt_xfer = cros_ec_pkt_xfer_lpc; > + ec_dev->xfer_fcn_owner = THIS_MODULE; You need to modify other transport modules as well: cros_ec_i2c.c, cros_ec_spi.c. > ec_dev->cmd_readmem = cros_ec_lpc_readmem; > ec_dev->din_size = sizeof(struct ec_host_response) + > sizeof(struct ec_response_get_protocol_info); > diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h > index 2d4e23c9ea0a..5239107e5091 100644 > --- a/include/linux/mfd/cros_ec.h > +++ b/include/linux/mfd/cros_ec.h > @@ -18,6 +18,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -139,6 +140,7 @@ struct cros_ec_device { > int dout_size; > bool wake_enabled; > bool suspended; > + struct module *xfer_fcn_owner; Another solution would be to make cros_ec a real module. lpc depends on cros_ec_register, so lsmod will not unload cros_ec [core functions] if cros_ec_lpc is still loaded. > int (*cmd_xfer)(struct cros_ec_device *ec, > struct cros_ec_command *msg); > int (*pkt_xfer)(struct cros_ec_device *ec, > -- > 2.17.1.1185.g55be947832-goog >