Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3784085ybc; Thu, 21 Nov 2019 13:44:58 -0800 (PST) X-Google-Smtp-Source: APXvYqyoC/dEI6sEaq0jkic7nkcCFyF6F2JVvdYQDWzgavkVtT9uEeft6BNuypsFnScRtHVTvJjl X-Received: by 2002:a17:906:9458:: with SMTP id z24mr16324209ejx.289.1574372698848; Thu, 21 Nov 2019 13:44:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574372698; cv=none; d=google.com; s=arc-20160816; b=j7TN7Fvs+B4YTt8wOYWx1+27Y8ErCnWdOUtNdg8VLtEexR18RvHU8wT7aV5hI7FyYp qDvpMSSV82jLq45y2vM+K4hKB2vCq80gsmYm235OlZ/+5Xd1GlgIOOr71xVCwUQ8eFdN pEw9zxCxRkM9XchFFo6m/2r34xzwPdyHX2Imjhhk6EOQBGf/32wFE3Ds5wH0KcVoAVq8 g4+BVo3YAXxHIA7puqvW+DXQElzp8SM4AENeiZ56J1udW/Uip6LF8iJcbWPh/AHixhYz mI2Wrl+TrifYKE+wkQyBJFLYqudLKdvE10QNmQN9I6U7q32SZoTUfoyUg5DvINqo5oGU eD/A== 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; bh=tR7zPw0NRIBlEH7Gx7mSFzrrOGPQV8KzgffSPPviA7M=; b=JMJOkSHYT7R9fr4NJgYI/NmWB12SYd/hboyFFs5CvJTElcd4poilvi+z7DEsskc4Hb PLyvUJ9XVhyr++3+OdNKLDR7phki4Xl6GBpRdl4IkrVOKDLdMi2sS3ReRKETtScQUo67 jlJh2PwhRlmtSDplVMz3ZUgL+fMA770nTKyQbNGluozQqOnuni2NKij6Y5m1OErHj801 tCUNoM4HbHeloI6ChvUTqIh3hrFRgnwgtxDswstAFim9LyThbRlwvE2RBPMQhSLWNDbn 9FgsXPWn72u8LQSTpM3Lm86eTmaSnCc+dZKNthqxLUy0v+zw9uhLCUVw8xS/Ferp8AWR HMCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ld86EQA0; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id la17si2977455ejb.433.2019.11.21.13.44.33; Thu, 21 Nov 2019 13:44:58 -0800 (PST) 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=@google.com header.s=20161025 header.b=Ld86EQA0; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726704AbfKUVkz (ORCPT + 99 others); Thu, 21 Nov 2019 16:40:55 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:44237 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfKUVkz (ORCPT ); Thu, 21 Nov 2019 16:40:55 -0500 Received: by mail-yw1-f65.google.com with SMTP id p128so1789423ywc.11 for ; Thu, 21 Nov 2019 13:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tR7zPw0NRIBlEH7Gx7mSFzrrOGPQV8KzgffSPPviA7M=; b=Ld86EQA0R1hOJ6sKkuqoxblruwPy6VQjEUfD9LsILZ/pXkITFpjk7hCHa700buT9cT 6I2WbMMtkwKDhmBRAF+koqT7jbdgXSTQjf33HLc365fgiMxqIzYS9lZ6gF0YGGyVDXkM wtjGPR9rIxnop4U3/iUAJAD9pe+2bRgKhHtAec4TeN59H1xdF2CtBzUpyJy9A41EVors sJO9jb3P6EeposVy4HDBXOGuybyTMF8OAs+osCjgksDatqKqnfUiensm1MSyDEFIlsub BmQcZdGcJno+6dvnyqxWHQMBSe829VLEO3Uc7pmGUBxKBAyw5g9WqsRZiD2m62MyKqom rMLQ== 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=tR7zPw0NRIBlEH7Gx7mSFzrrOGPQV8KzgffSPPviA7M=; b=UW6FQiSBVpBCI8l8qE72ysSqE24BgF9UVRnOfyaP2eIsaiPXfYJDZsek496Q6B4NmW 0fZenmiH/82xjC1l6LnmV9yeJxIwy2M94TFWObBNz/SDMWZPusRxDnG4e7TJ7ubjaD0t ofEgb80QDqaT2yrkX1pqo3qTkPKZlIq5BGsGtx+MoOgWtz1qlZMq+kg22EXqabRB18lj AAykCLACgF1uH9ArwNXByGrYvGxRbMmIoAvPdPQO1ttX3wCgXqaMGth4R0zcEaGtj1Zy GQr4XMH0YiB6L60BqbvofdJ2kwrSemtwb+Aeo7XjDiw2oWfrrbd3W3COIM0QGQWdA+Qm Pu6Q== X-Gm-Message-State: APjAAAVanq5S0VbVCFeOiMafygiKNBzdAj59x+IfIExkRPu1wtya3P5F f2mtzdrRyotahOdBmuV7m55mmOu/WDkZPsI8SdNqGQ== X-Received: by 2002:a81:3c91:: with SMTP id j139mr6737132ywa.371.1574372453557; Thu, 21 Nov 2019 13:40:53 -0800 (PST) MIME-Version: 1.0 References: <20191121211053.48861-1-rrangel@chromium.org> <20191121140830.4.Iddc7dd74f893297cb932e9825d413e7890633b3d@changeid> In-Reply-To: <20191121140830.4.Iddc7dd74f893297cb932e9825d413e7890633b3d@changeid> From: Guenter Roeck Date: Thu, 21 Nov 2019 13:40:42 -0800 Message-ID: Subject: Re: [PATCH 4/4] platform/chrome: i2c: i2c-cros-ec-tunnel: Convert i2c tunnel to MFD Cell To: Raul E Rangel Cc: Enric Balletbo i Serra , Wolfram Sang , Akshu.Agrawal@amd.com, Guenter Roeck , Chanwoo Choi , linux-kernel , Alexandre Belloni , linux-i2c@vger.kernel.org, Lee Jones , Benson Leung 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 Thu, Nov 21, 2019 at 1:11 PM Raul E Rangel wrote: > > If the i2c-cros-ec-tunnel driver is compiled into the kernel, it is > possible that i2c-cros-ec-tunnel could be probed before cros_ec_XXX > has finished initializing and setting the drvdata. This would cause a > NULL pointer panic. > > Converting this driver over to an MFD solves the problem and aligns with > where the cros_ec is going. > I thought the mfd maintainer objects to the use of the mfd API outside drivers/mfd. Did that change recently ? Guenter > Signed-off-by: Raul E Rangel > --- > You can now see the device node lives under the mfd device. > > $ find /sys/bus/platform/devices/cros-ec-dev.0.auto/cros-ec-i2c-tunnel.12.auto/ -iname firmware_node -exec ls -l '{}' \; > /sys/bus/platform/devices/cros-ec-dev.0.auto/cros-ec-i2c-tunnel.12.auto/firmware_node -> ../../../../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:1c/PNP0C09:00/GOOG0004:00/GOOG0012:00 > /sys/bus/platform/devices/cros-ec-dev.0.auto/cros-ec-i2c-tunnel.12.auto/i2c-9/firmware_node -> ../../../../../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:1c/PNP0C09:00/GOOG0004:00/GOOG0012:00 > /sys/bus/platform/devices/cros-ec-dev.0.auto/cros-ec-i2c-tunnel.12.auto/i2c-9/i2c-10EC5682:00/firmware_node -> ../../../../../../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:1c/PNP0C09:00/GOOG0004:00/GOOG0012:00/10EC5682:00 > > drivers/i2c/busses/i2c-cros-ec-tunnel.c | 36 +++++++++---------------- > drivers/mfd/cros_ec_dev.c | 19 +++++++++++++ > 2 files changed, 32 insertions(+), 23 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-cros-ec-tunnel.c b/drivers/i2c/busses/i2c-cros-ec-tunnel.c > index 5d91e33eb600..2e3217678fa3 100644 > --- a/drivers/i2c/busses/i2c-cros-ec-tunnel.c > +++ b/drivers/i2c/busses/i2c-cros-ec-tunnel.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -27,7 +28,6 @@ > struct ec_i2c_device { > struct device *dev; > struct i2c_adapter adap; > - struct cros_ec_device *ec; > > u16 remote_bus; > > @@ -176,6 +176,7 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[], > { > struct ec_i2c_device *bus = adap->algo_data; > struct device *dev = bus->dev; > + struct cros_ec_dev *ec = dev_get_drvdata(dev->parent); > const u16 bus_num = bus->remote_bus; > int request_len; > int response_len; > @@ -183,6 +184,16 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[], > int result; > struct cros_ec_command *msg; > > + if (!ec) { > + dev_err(dev, "%s: ec is missing!\n", __func__); > + return -EINVAL; > + } > + > + if (!ec->ec_dev) { > + dev_err(dev, "%s: ec->ec_dev is missing!\n", __func__); > + return -EINVAL; > + } > + > request_len = ec_i2c_count_message(i2c_msgs, num); > if (request_len < 0) { > dev_warn(dev, "Error constructing message %d\n", request_len); > @@ -212,7 +223,7 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[], > msg->outsize = request_len; > msg->insize = response_len; > > - result = cros_ec_cmd_xfer_status(bus->ec, msg); > + result = cros_ec_cmd_xfer_status(ec->ec_dev, msg); > if (result < 0) { > dev_err(dev, "Error transferring EC i2c message %d\n", result); > goto exit; > @@ -241,17 +252,11 @@ static const struct i2c_algorithm ec_i2c_algorithm = { > > static int ec_i2c_probe(struct platform_device *pdev) > { > - struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); > struct device *dev = &pdev->dev; > struct ec_i2c_device *bus = NULL; > u32 remote_bus; > int err; > > - if (!ec->cmd_xfer) { > - dev_err(dev, "Missing sendrecv\n"); > - return -EINVAL; > - } > - > bus = devm_kzalloc(dev, sizeof(*bus), GFP_KERNEL); > if (bus == NULL) > return -ENOMEM; > @@ -263,7 +268,6 @@ static int ec_i2c_probe(struct platform_device *pdev) > } > bus->remote_bus = remote_bus; > > - bus->ec = ec; > bus->dev = dev; > > bus->adap.owner = THIS_MODULE; > @@ -292,25 +296,11 @@ static int ec_i2c_remove(struct platform_device *dev) > return 0; > } > > -static const struct of_device_id cros_ec_i2c_of_match[] = { > - { .compatible = "google,cros-ec-i2c-tunnel" }, > - {}, > -}; > -MODULE_DEVICE_TABLE(of, cros_ec_i2c_of_match); > - > -static const struct acpi_device_id cros_ec_i2c_tunnel_acpi_id[] = { > - { "GOOG0012", 0 }, > - { } > -}; > -MODULE_DEVICE_TABLE(acpi, cros_ec_i2c_tunnel_acpi_id); > - > static struct platform_driver ec_i2c_tunnel_driver = { > .probe = ec_i2c_probe, > .remove = ec_i2c_remove, > .driver = { > .name = "cros-ec-i2c-tunnel", > - .acpi_match_table = ACPI_PTR(cros_ec_i2c_tunnel_acpi_id), > - .of_match_table = of_match_ptr(cros_ec_i2c_of_match), > }, > }; > > diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c > index 1efdba18f20b..61b20e061f75 100644 > --- a/drivers/mfd/cros_ec_dev.c > +++ b/drivers/mfd/cros_ec_dev.c > @@ -113,6 +113,18 @@ static const struct mfd_cell cros_ec_vbc_cells[] = { > { .name = "cros-ec-vbc", } > }; > > +static struct mfd_cell_acpi_match cros_ec_i2c_tunnel_acpi_match = { > + .pnpid = "GOOG0012" > +}; > + > +static struct mfd_cell cros_ec_fw_cells[] = { > + { > + .name = "cros-ec-i2c-tunnel", > + .acpi_match = &cros_ec_i2c_tunnel_acpi_match, > + .of_compatible = "google,cros-ec-i2c-tunnel" > + }, > +}; > + > int cros_ec_check_features(struct cros_ec_dev *ec, int feature) > { > struct cros_ec_command *msg; > @@ -485,6 +497,13 @@ static int ec_device_probe(struct platform_device *pdev) > "failed to add cros-ec platform devices: %d\n", > retval); > > + retval = mfd_add_hotplug_devices(ec->dev, cros_ec_fw_cells, > + ARRAY_SIZE(cros_ec_fw_cells)); > + if (retval) > + dev_warn(ec->dev, > + "failed to add cros-ec fw platform devices: %d\n", > + retval); > + > /* Check whether this EC instance has a VBC NVRAM */ > node = ec->ec_dev->dev->of_node; > if (of_property_read_bool(node, "google,has-vbc-nvram")) { > -- > 2.24.0.432.g9d3f5f5b63-goog >