Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1625479ybp; Wed, 9 Oct 2019 17:44:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqruz6Z3wMSaRxQF8uPDvneXY6HQ3S1CdHSByFkUjorxjFpzu0UNR/FqMY3ioC6yBpsX3W X-Received: by 2002:a17:906:264f:: with SMTP id i15mr5524430ejc.333.1570668262815; Wed, 09 Oct 2019 17:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570668262; cv=none; d=google.com; s=arc-20160816; b=uzNjnSbY5jpaypkSgmW9a0EEER7Nsh8y6NRtpyhR1WcesT9ZQVWdI6gWzImVzhmOE3 XQOOadftq4tALiroZmztK5vBcIxNLuL722c/pBaL201BALrCjUjmvW//Tge2qeDKYmij CWFmf0+2IVcePAaTplrEetIu98X2JoREGaY2R3eDbMfP/Uteyx8FfefqGuiBQ8CkkiCe 7ZaEnxrOh7k4wOydl6rw6yxZZcHyT1jLaspuyANX1VZ5+fTQLkHfpa4MJU2BrnzX0FZY wwUNkVFOFh6h3Xgs7/atznfegfRA5Mmlykp3Zg7nKNu6wQ+/hgZlH5e7Ji48sfILp216 aVzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=EmpLSZbGnESFw5BRu3T9oQ2vsLPNikHLnrHZ4E2SsuQ=; b=LuMxmUp7vLRCyo5DORaRpPnCsdEGSmPjWqNrR3rjX95216g77vHdLmH866QbQgEwdO aLW8Jtps97y15D7O6EYsG4lGeEId6gO7bf04virfnowCVAs3LocTKqKxVgB7TkM41Oua Cggw7uZJOBzuAw6qHxRx/1mL8BleByLXI3ZTBHAOkjr8lFUAEAmKdkOuK2EC/KBoJjSU vtnnuxVXs3+E2WBaETY/RyQisaNUGjeixv2lMf80gI6MlTBOKjZ0ePrJDARVfRL4Fx60 xoRwP3fG0Zw/pL+mTfVzRIYLk7rqmhvxneIOfvf2yHpxeXu0Olm5DDleD/xqb3MwR3qL 8XbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=b7WWtw1q; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d14si2135440ejr.358.2019.10.09.17.43.58; Wed, 09 Oct 2019 17:44:22 -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=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=b7WWtw1q; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732530AbfJJAkk (ORCPT + 99 others); Wed, 9 Oct 2019 20:40:40 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:37827 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732504AbfJJAkj (ORCPT ); Wed, 9 Oct 2019 20:40:39 -0400 Received: by mail-qt1-f194.google.com with SMTP id l51so5933201qtc.4 for ; Wed, 09 Oct 2019 17:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=EmpLSZbGnESFw5BRu3T9oQ2vsLPNikHLnrHZ4E2SsuQ=; b=b7WWtw1q5NY5f4d8hbqlFYATElioKhsFMKy3jfvgJqtJGssk/ZrOpgoM+Cm7xH9Sih t7TgqcnNx6GJBiqNxWCSP6af6PmecWBHVDtDxcBEi0PNzkY714XlWiNXg0r+b6rCVJtI M1TRlgAEVdgyLp0D+aJx/xl3JrZB/2RRtr1eStVB+RVYub7RbEoFp9Cql4tl5Qg6n+ze dt+vw3tyQz4BZ2TSDznhVJOb7k8O+ylNt9gPS8G83u6Qirendn5QhSVbVZrhja1Y7arP AMbSuyqQakrAZRptMsbbP7HprUuDhtWC/P7HjOVQ3M83P/iSWfzoNU1JPEnhgKblQsPL 66qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=EmpLSZbGnESFw5BRu3T9oQ2vsLPNikHLnrHZ4E2SsuQ=; b=XnZDBW7oxMc3Nh3gYPNaADLyxg3SvZ+5q2MR6RP7sWr6n/h9f7zS3pN0GMNvXmz2kW LWQWqeMKfwPc8Why3p4r2Xsy9dQGMbclogQZc3Z08nGxteQGDMG4tI5om54M2rI51i/y 2JMs9xjHi5blrzqZ8YsD+wqbGf2WJtzk4dKj96J7yU+2GJysCAmB550bf/n+YHjPvjKM rakni7gAWJonNpSa+ew2IayLkur/BS3bPUz42Reue+nfUZMa9j6SUYns4kpE0hiY0/lD CEsZ0LNZ2Ju+hQSlgL8CAQcGkU5bFiRXROmMlyN9N8Xur2tFfLxPPC7A6Na+IyUnnoLG FXrA== X-Gm-Message-State: APjAAAXbEVEDy3X+4kbJtrRvwNVYeenbI6iUBTxKbPfKJHbIj8OpQrJA 4MEEGcAVRsD4HxknRUvyFzeD+g== X-Received: by 2002:ac8:f28:: with SMTP id e37mr7140558qtk.274.1570668038323; Wed, 09 Oct 2019 17:40:38 -0700 (PDT) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id q44sm2594824qtk.16.2019.10.09.17.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 17:40:38 -0700 (PDT) Date: Wed, 9 Oct 2019 17:40:23 -0700 From: Jakub Kicinski To: Lars Poeschel Cc: Jilayne Lovejoy , Kate Stewart , Allison Randal , Greg Kroah-Hartman , Thomas Gleixner , Steve Winslow , "Gustavo A. R. Silva" , Johan Hovold , netdev@vger.kernel.org (open list:NFC SUBSYSTEM), linux-kernel@vger.kernel.org (open list), Claudiu Beznea Subject: Re: [PATCH v9 4/7] nfc: pn533: Split pn533 init & nfc_register Message-ID: <20191009174023.528c278b@cakuba.netronome.com> In-Reply-To: <20191008140544.17112-5-poeschel@lemonage.de> References: <20191008140544.17112-1-poeschel@lemonage.de> <20191008140544.17112-5-poeschel@lemonage.de> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 8 Oct 2019 16:05:41 +0200, Lars Poeschel wrote: > There is a problem in the initialisation and setup of the pn533: It > registers with nfc too early. It could happen, that it finished > registering with nfc and someone starts using it. But setup of the pn533 > is not yet finished. Bad or at least unintended things could happen. > So I split out nfc registering (and unregistering) to seperate functions > that have to be called late in probe then. > > Cc: Johan Hovold > Cc: Claudiu Beznea > Signed-off-by: Lars Poeschel > diff --git a/drivers/nfc/pn533/i2c.c b/drivers/nfc/pn533/i2c.c > index 1abd40398a5a..e9e5a1ec8857 100644 > --- a/drivers/nfc/pn533/i2c.c > +++ b/drivers/nfc/pn533/i2c.c > @@ -193,12 +193,10 @@ static int pn533_i2c_probe(struct i2c_client *client, > phy->i2c_dev = client; > i2c_set_clientdata(client, phy); > > - priv = pn533_register_device(PN533_DEVICE_PN532, > - PN533_NO_TYPE_B_PROTOCOLS, > + priv = pn53x_common_init(PN533_DEVICE_PN532, > PN533_PROTO_REQ_ACK_RESP, > phy, &i2c_phy_ops, NULL, > - &phy->i2c_dev->dev, > - &client->dev); > + &phy->i2c_dev->dev); nit: start of continuation lines should match the opening parenthesis, please run checkpatch and fix the style issue > if (IS_ERR(priv)) { > r = PTR_ERR(priv); > @@ -220,13 +218,17 @@ static int pn533_i2c_probe(struct i2c_client *client, > if (r) > goto fn_setup_err; > > - return 0; > + r = pn53x_register_nfc(priv, PN533_NO_TYPE_B_PROTOCOLS, &client->dev); > + if (r) > + goto fn_setup_err; > + > + return r; > > fn_setup_err: > free_irq(client->irq, phy); > > irq_rqst_err: > - pn533_unregister_device(phy->priv); > + pn53x_common_clean(phy->priv); > > return r; > } > @@ -239,7 +241,8 @@ static int pn533_i2c_remove(struct i2c_client *client) > > free_irq(client->irq, phy); > > - pn533_unregister_device(phy->priv); > + pn53x_unregister_nfc(phy->priv); > + pn53x_common_clean(phy->priv); > > return 0; > } > diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c > index 64836c727aee..e5d5e4c83a04 100644 > --- a/drivers/nfc/pn533/pn533.c > +++ b/drivers/nfc/pn533/pn533.c > @@ -2590,14 +2590,12 @@ int pn533_finalize_setup(struct pn533 *dev) > } > EXPORT_SYMBOL_GPL(pn533_finalize_setup); > > -struct pn533 *pn533_register_device(u32 device_type, > - u32 protocols, > +struct pn533 *pn53x_common_init(u32 device_type, > enum pn533_protocol_type protocol_type, > void *phy, > struct pn533_phy_ops *phy_ops, > struct pn533_frame_ops *fops, > - struct device *dev, > - struct device *parent) > + struct device *dev) > { > struct pn533 *priv; > int rc = -ENOMEM; > @@ -2638,43 +2636,18 @@ struct pn533 *pn533_register_device(u32 device_type, > skb_queue_head_init(&priv->fragment_skb); > > INIT_LIST_HEAD(&priv->cmd_queue); > - > - priv->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols, > - priv->ops->tx_header_len + > - PN533_CMD_DATAEXCH_HEAD_LEN, > - priv->ops->tx_tail_len); > - if (!priv->nfc_dev) { > - rc = -ENOMEM; > - goto destroy_wq; > - } > - > - nfc_set_parent_dev(priv->nfc_dev, parent); > - nfc_set_drvdata(priv->nfc_dev, priv); > - > - rc = nfc_register_device(priv->nfc_dev); > - if (rc) > - goto free_nfc_dev; Aren't you moving too much out of here? Looking at commit 32ecc75ded72 ("NFC: pn533: change order operations in dev registation") it seems like IRQ handler may want to access the data structures, do this change not reintroduce the problem? > return priv; > > -free_nfc_dev: > - nfc_free_device(priv->nfc_dev); > - > -destroy_wq: > - destroy_workqueue(priv->wq); > error: > kfree(priv); > return ERR_PTR(rc); > } > -EXPORT_SYMBOL_GPL(pn533_register_device); > +EXPORT_SYMBOL_GPL(pn53x_common_init); > > -void pn533_unregister_device(struct pn533 *priv) > +void pn53x_common_clean(struct pn533 *priv) > { > struct pn533_cmd *cmd, *n; > > - nfc_unregister_device(priv->nfc_dev); > - nfc_free_device(priv->nfc_dev); > - > flush_delayed_work(&priv->poll_work); > destroy_workqueue(priv->wq); >