From patchwork Thu Jun 9 08:53:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 632684 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rQJz523szz9s5Q for ; Thu, 9 Jun 2016 18:54:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=IUoCVlW6; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422723AbcFIIyX (ORCPT ); Thu, 9 Jun 2016 04:54:23 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36692 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161294AbcFIIyR (ORCPT ); Thu, 9 Jun 2016 04:54:17 -0400 Received: by mail-wm0-f66.google.com with SMTP id m124so8806043wme.3; Thu, 09 Jun 2016 01:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t7j0C497pBGk8yTs0Vj6peuGIrA5CVCDZYMUPYF3kOo=; b=IUoCVlW6pKtDwICKXyyB7TtDrh6gfFksums0ZyflzfLoXeIuLlVJ5mvLu32t2uLBt2 IOBJFR1rARtJ9rj+a+z6APYWNMvkTNK5AXG3TZz9mKLwVMQW1JMS2zWOzuErv150JpAz 9CqqHsvDWFRq1RPtKriSK6AeET8MeMwHT1zE7uLF0kNY8UOKUQfCBqsv/xy+SnFmzH1K TQvQwAU4YqYjoa7kBgCjWNfnQWv07578Gn6WSj/VMBqt2KFcdsYpjgrPH5tisKGT7BJZ X1jVC9pAc//uRduazNX6VHOROLV4hE+5dFobasOENh/N6lPQpUTBh1hW5atIEnnOnC+Q vLsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=t7j0C497pBGk8yTs0Vj6peuGIrA5CVCDZYMUPYF3kOo=; b=Ry1jU79QFxkErc5C3QQOFqohdzO56Tmr2iYqlswJVOiEn504XtHrfb0fycATDFSErQ /+QaxCpjlJvMSzk+EfTjB7uiQwegLa1VsweMnPJTeDoE5vpvT1KanCuNLB7f0Ly6dDFu yYfafjKYPxMdb4ycJIKEpn3rYClBOK3xJ2bDQoiswuaBFTxmUO00jKjnn52ZocjNXTh8 eqmOS9aPLT7IKTgy4PoPmiFGTSFgMw2wl08yxB2aGONjFyzkjHlvOtpndidysr68V+dC ROM8AzVsMsOaDzBg5bhOJoVci+loh5WRK5924LMDsDvPB19+ItoEPyDzZC1W4LRQdny7 4NsA== X-Gm-Message-State: ALyK8tLzq1MhF3NTjy1XJhjw7WwfByPqxBRFrJkrM1ATmvzPgk4jEmb6lyfIQiCClLKaNg== X-Received: by 10.28.215.148 with SMTP id o142mr11456498wmg.72.1465462455872; Thu, 09 Jun 2016 01:54:15 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id x128sm3901916wmf.6.2016.06.09.01.54.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jun 2016 01:54:15 -0700 (PDT) From: Chris Wilson To: linux-i2c@vger.kernel.org Cc: Chris Wilson , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Wolfram Sang , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] i2c: Mark adapter as initialised Date: Thu, 9 Jun 2016 09:53:54 +0100 Message-Id: <1465462435-5240-2-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465462435-5240-1-git-send-email-chris@chris-wilson.co.uk> References: <1465462435-5240-1-git-send-email-chris@chris-wilson.co.uk> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In order to allow drivers to call i2c_init_adapter as a separate step, and to allow other drivers to continue skipping the call, mark the adapter as initialised upon i2c_init_adapter() and ignore multiple calls. The choice of how to introduce an "already-initialised" check into the existing i2c_add_adapter() callers is tricky as we cannot make too many assumptions about the state of memory, i.e. whether the struct was cleared before being passed to i2c_add_adapter. This poses an issue if we wanted to add a boolean flag to mark when the adapter is initialised (as that flag may be set due to previous contents of memory). Instead, we opt to use the userspace_client_lists as that should be empty from initialisation through to registration - but will be reported as !empty if it has either random junk or zeroes (with a very small chance that we fail to register an adapter that just happens to have a prior empty list at that location in memory). Signed-off-by: Chris Wilson Cc: Ville Syrjälä Cc: Wolfram Sang Cc: linux-i2c@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org --- drivers/i2c/i2c-core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 743c38a63da1..91ff70d31ec8 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1513,6 +1513,10 @@ static int __process_new_adapter(struct device_driver *d, void *data) static int i2c_init_adapter(struct i2c_adapter *adap) { + /* Only initialise the adapter once. */ + if (list_empty(&adap->userspace_clients)) + return 0; + /* Sanity checks */ if (unlikely(adap->name[0] == '\0')) { pr_err("i2c-core: Attempt to register an adapter with " @@ -1632,6 +1636,9 @@ out_list: mutex_lock(&core_lock); idr_remove(&i2c_adapter_idr, adap->nr); mutex_unlock(&core_lock); + + /* Force initialisation if this struct gets reused */ + memset(&adap->userspace_clients, 0, sizeof(adap->userspace_clients)); return res; }