From patchwork Wed Aug 9 18:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 133438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp3018839vqr; Wed, 9 Aug 2023 12:15:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsG+IMBMDqGtCTWTh2jODbbGOL3FsCbd5+4TkCiltDdX7hqWI/T1pF672BUilZtqUhPwsW X-Received: by 2002:a05:6512:6c7:b0:4fe:7e7f:1328 with SMTP id u7-20020a05651206c700b004fe7e7f1328mr38062lff.16.1691608549193; Wed, 09 Aug 2023 12:15:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691608549; cv=none; d=google.com; s=arc-20160816; b=FtCEsL4kodcSq2IxJd+GX7JOKccaCMmDsXKZJ44tf+6EbwyNWmbe0cD1ISt2SYvbEe RD9UczqNhm39yU2SzCHMG2akizuVgS/rwl38jEpKvCWKgqwhAPVSZR5K8xtu/Dr/3v+8 j7CcPQar8k9vkqdWLAJ1AI0WC7XSjNxTkZoFqwaU95D98CRPjUS/wMHQIHqzcchkvdzv 0JsIZorw+WiRGmxTqFLYXy19STCTA1dlaoWGG2ALD1sLEDYle9DfgsXFzINs1tSegkex qD4WOjve0Idka4YXllNCF7IwAjAifc+o4MzK4gVm3Ztk0n47qBlR2FobimiQg/rgPY8m pQ/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mZ7AOPMxHb6FKBNdsHN1v7pPOshgYKsxrob+a/3XGRU=; fh=Nk+rQs0tlXXO574yDiVc+8hCPRXCCJXlaK0kyNydf+U=; b=S37q+GI+CkqUmsttn0BOY9waaefcjzsmg5/WepUKGTZ9fG6agCoCP5tCemqlYKpnWg Xl7Zyxr93HzsXmK6IXksEhGTaT3Qto+7DOFv/iBf5+vHHxLKd3HL0sMdEqq5NDsVQXpc xUYCBOCRq2fjt+EvZty6WrDvlkdQ1ZzO/VVZDDehKxmS+IS33z/rhsjdNfPWDIC3jgas vhcCn3SDAvq+URk06ve7wcUwMabm1oVgjwF6whSnUMaxDiALPch14/qQL1vdQxJfd0m6 UassYdHq6FBCQ55XsGu4hEtxOeiqxBkF36qURHPLpUSms2aLrrpxE4CdIKnaQpyptvIz k9vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=ht3pxNWJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a05640214d100b005234684a7e2si3164449edx.119.2023.08.09.12.15.25; Wed, 09 Aug 2023 12:15:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=ht3pxNWJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbjHISIm (ORCPT + 99 others); Wed, 9 Aug 2023 14:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbjHISIi (ORCPT ); Wed, 9 Aug 2023 14:08:38 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2F651736 for ; Wed, 9 Aug 2023 11:08:36 -0700 (PDT) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 379Hw2XQ029123; Wed, 9 Aug 2023 18:08:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=mZ7AOPMxHb6FKBNdsHN1v7pPOshgYKsxrob+a/3XGRU=; b=ht3pxNWJ4JN2VqY74R6jBpoSryo+0rk0Uc/Chgpzrl25Kv74hpBa8OxDxBxyKDxmZCIX +8pStwOxkr4auCRQH1imAtyKGf2bGbKDAqKgp4agc9y7md9BOLsGbBXeISa2zAYeslbI ecwqD50o9lhcdHZluqfWQ2C8lvM+15qFTGPFiBRIjtH41AqbP2bRoki1CB5pka64m8Jq /lHbVmGcGv3i8LQ1sgs/WQGqXFDdw/q3EaIQmcj/q6BFflhvkvUNXNscFPuDYt4rpYEG qGQ0NR6DbDaKXcCPLSnb7AZ0OlHyvc1v6GulSUIi6EVybJ//RoxEtf0gzZIuiXsx/E4f 7A== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3scfnt0aa2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Aug 2023 18:08:20 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 379Gftgh007543; Wed, 9 Aug 2023 18:08:20 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sa14yjvnd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Aug 2023 18:08:20 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 379I8JPX27918930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Aug 2023 18:08:19 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DE6A58059; Wed, 9 Aug 2023 18:08:19 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 054D458043; Wed, 9 Aug 2023 18:08:19 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.73.158]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 9 Aug 2023 18:08:18 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: joel@jms.id.au, linux-kernel@vger.kernel.org, alistair@popple.id.au, k@ozlabs.org, Eddie James Subject: [PATCH 1/2] fsi: Improve master indexing Date: Wed, 9 Aug 2023 13:08:13 -0500 Message-Id: <20230809180814.151984-2-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230809180814.151984-1-eajames@linux.ibm.com> References: <20230809180814.151984-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YgUUKjKqE9imD0Wjm7hpCvAkPjXMvknu X-Proofpoint-ORIG-GUID: YgUUKjKqE9imD0Wjm7hpCvAkPjXMvknu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-09_14,2023-08-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 malwarescore=0 clxscore=1015 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308090158 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1768528317865067576 X-GMAIL-MSGID: 1773780126072377108 Master indexing is problematic if a hub is rescanned while the root master is being rescanned. Always allocate an index for the FSI master, and set the device name if it hasn't already been set. Move the call to ida_free to the bottom of master unregistration and set the number of links to 0 in case another call to scan comes in before the device is removed. Signed-off-by: Eddie James --- drivers/fsi/fsi-core.c | 24 +++++++++++++++--------- drivers/fsi/fsi-master-i2cr.c | 4 +--- drivers/fsi/fsi-master-i2cr.h | 9 +++++++++ drivers/fsi/fsi-master.h | 1 - drivers/fsi/i2cr-scom.c | 2 +- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index 86b3108ea753..c7a002076292 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -1310,13 +1310,19 @@ int fsi_master_register(struct fsi_master *master) mutex_init(&master->scan_lock); - if (!master->idx) { + /* Alloc the requested index if it's non-zero */ + if (master->idx) { + master->idx = ida_alloc_range(&master_ida, master->idx, + master->idx, GFP_KERNEL); + } else { master->idx = ida_alloc(&master_ida, GFP_KERNEL); - if (master->idx < 0) - return master->idx; + } + + if (master->idx < 0) + return master->idx; + if (!dev_name(&master->dev)) dev_set_name(&master->dev, "fsi%d", master->idx); - } master->dev.class = &fsi_master_class; @@ -1339,17 +1345,17 @@ EXPORT_SYMBOL_GPL(fsi_master_register); void fsi_master_unregister(struct fsi_master *master) { - trace_fsi_master_unregister(master); + int idx = master->idx; - if (master->idx >= 0) { - ida_free(&master_ida, master->idx); - master->idx = -1; - } + trace_fsi_master_unregister(master); mutex_lock(&master->scan_lock); fsi_master_unscan(master); + master->n_links = 0; mutex_unlock(&master->scan_lock); + device_unregister(&master->dev); + ida_free(&master_ida, idx); } EXPORT_SYMBOL_GPL(fsi_master_unregister); diff --git a/drivers/fsi/fsi-master-i2cr.c b/drivers/fsi/fsi-master-i2cr.c index e4e8a5931ca3..61659c27a973 100644 --- a/drivers/fsi/fsi-master-i2cr.c +++ b/drivers/fsi/fsi-master-i2cr.c @@ -267,13 +267,12 @@ static int i2cr_probe(struct i2c_client *client) /* Only one I2CR on any given I2C bus (fixed I2C device address) */ i2cr->master.idx = client->adapter->nr; - dev_set_name(&i2cr->master.dev, "i2cr%d",i2cr->master.idx); + dev_set_name(&i2cr->master.dev, "i2cr%d", i2cr->master.idx); i2cr->master.dev.parent = &client->dev; i2cr->master.dev.of_node = of_node_get(dev_of_node(&client->dev)); i2cr->master.dev.release = i2cr_release; i2cr->master.n_links = 1; - i2cr->master.flags = FSI_MASTER_FLAG_I2CR; i2cr->master.read = i2cr_read; i2cr->master.write = i2cr_write; @@ -292,7 +291,6 @@ static void i2cr_remove(struct i2c_client *client) { struct fsi_master_i2cr *i2cr = i2c_get_clientdata(client); - i2cr->master.idx = -1; fsi_master_unregister(&i2cr->master); } diff --git a/drivers/fsi/fsi-master-i2cr.h b/drivers/fsi/fsi-master-i2cr.h index 929d63995c7b..96636bf28cac 100644 --- a/drivers/fsi/fsi-master-i2cr.h +++ b/drivers/fsi/fsi-master-i2cr.h @@ -4,6 +4,7 @@ #ifndef DRIVERS_FSI_MASTER_I2CR_H #define DRIVERS_FSI_MASTER_I2CR_H +#include #include #include "fsi-master.h" @@ -21,4 +22,12 @@ struct fsi_master_i2cr { int fsi_master_i2cr_read(struct fsi_master_i2cr *i2cr, u32 addr, u64 *data); int fsi_master_i2cr_write(struct fsi_master_i2cr *i2cr, u32 addr, u64 data); +static inline bool is_fsi_master_i2cr(struct fsi_master *master) +{ + if (master->dev.parent && master->dev.parent->type == &i2c_client_type) + return true; + + return false; +} + #endif /* DRIVERS_FSI_MASTER_I2CR_H */ diff --git a/drivers/fsi/fsi-master.h b/drivers/fsi/fsi-master.h index a1fa315849d2..967622c1cabf 100644 --- a/drivers/fsi/fsi-master.h +++ b/drivers/fsi/fsi-master.h @@ -111,7 +111,6 @@ /* fsi-master definition and flags */ #define FSI_MASTER_FLAG_SWCLOCK 0x1 -#define FSI_MASTER_FLAG_I2CR 0x2 /* * Structures and function prototypes diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c index 63b548bdef3e..cb7e02213032 100644 --- a/drivers/fsi/i2cr-scom.c +++ b/drivers/fsi/i2cr-scom.c @@ -88,7 +88,7 @@ static int i2cr_scom_probe(struct device *dev) int didx; int ret; - if (!(fsi_dev->slave->master->flags & FSI_MASTER_FLAG_I2CR)) + if (!is_fsi_master_i2cr(fsi_dev->slave->master)) return -ENODEV; scom = devm_kzalloc(dev, sizeof(*scom), GFP_KERNEL); From patchwork Wed Aug 9 18:08:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 133421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2999209vqr; Wed, 9 Aug 2023 11:38:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhGtaHz6Bd0K9LZH8gGr6DU7H1o6t/lfBNwz9EVNcpj5BAEonzXwydqClRhk/QPpWsflPN X-Received: by 2002:a05:6870:eaa8:b0:1bf:ec67:f2c6 with SMTP id s40-20020a056870eaa800b001bfec67f2c6mr68848oap.17.1691606312972; Wed, 09 Aug 2023 11:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691606312; cv=none; d=google.com; s=arc-20160816; b=ncjn+B0nd6087PiRAZ5wnxBhCsk5cRlizSQnlaPsXvbVNJTMmGyPYEi+uoIzoQMZXP mqEKLAquT3xiZ87PLspH812ILiC98tlXr49GG34AVpmAztAB/3FVp1yvCrglRLp2UfE9 aJwTCs+zgMw++qYQXGXpEX8ZDFHT+XIyeITPUm46snSLMkB3pMlmJF/th9b2oNuV4WMq tNVtnwK86009lAjWc7MVn2lEv3VjJY877jFQLcz3dGkptgAIQ3wrvi8CgQRvLrsfD2Dq il/8pPL+RzwnAvId4HomSbvmmJgxbM2+O51qW81ot8fhplbAd2cys3uKPRIT46GSJXvt 4ERw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gYVoYXJeTSjHj2ebbtZoiLo5JrPxgiu6wu4sayq6J4s=; fh=Nk+rQs0tlXXO574yDiVc+8hCPRXCCJXlaK0kyNydf+U=; b=VJrVKWgGxY/p5VCC5VjdKfyrFoWF6ypNjasRWtTzjfnRuTUwlGfJZuaNB3D6iVej8q W5IcDWihdQCvUBYBO8LH2RwiDYhydVe+NndfaMXsscDxmDvGQRmnWh/HFeqMhH7p7dNC Fq6B6DD0BePK4TVaK1kahUdf4KB9QhJkyLFdwHA1q0SXhFBAMDNDF/6RR4bJ7nwEiXJ2 kQQi28RjvzQG8XqWyKLoZNXOlhHVuBKwAXRthAhOANP9ydcsThykwxKnPwmRm0Lv8yR9 rHpOfn0VwQolDNIom3ws+RqXRMD15CZNK/8y0bjKoCLmMQt6eo8unC4fRXjM1TY0URo9 1W3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="nfJ+8Mw/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h27-20020a63121b000000b005641697e83asi9511304pgl.131.2023.08.09.11.38.19; Wed, 09 Aug 2023 11:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="nfJ+8Mw/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbjHISIj (ORCPT + 99 others); Wed, 9 Aug 2023 14:08:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230172AbjHISIg (ORCPT ); Wed, 9 Aug 2023 14:08:36 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EA8F171D for ; Wed, 9 Aug 2023 11:08:36 -0700 (PDT) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 379HrJNB005981; Wed, 9 Aug 2023 18:08:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=gYVoYXJeTSjHj2ebbtZoiLo5JrPxgiu6wu4sayq6J4s=; b=nfJ+8Mw/05eiYAjXGNE3X4MOzsXAWBACaAyDXBm1dP1k8ycxIAc1BR2qp9dcbc+kmyH7 i81HQEec7VDbNTRAvOYgRKL6xanhkIKNwscBCAwyQ6N3gXDrfbcXPK03b0y3jHm8DC+6 f9AHOilnI2iNAPLmJ5081UtxHHNM7iVOGiVqhXgUZGNB2va2kXC0GH6d1TuG6zuYbH0m iE7oNiszdD0A7xUUuRtD9bsPxZxRgc/oe0iRfifeDYJ98uQpHDnT5dXamplTvZOSHmbB v+jNtvrCSLsS0a4FZ6tP5W22Jyb6mHt3l0JT9ytc4bN+Y04dQsoScSxHsO5l+Y79Xx+A KQ== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3scfkjrfgj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Aug 2023 18:08:21 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 379HppuY000402; Wed, 9 Aug 2023 18:08:20 GMT Received: from smtprelay01.wdc07v.mail.ibm.com ([172.16.1.68]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sa28ktc3y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Aug 2023 18:08:20 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay01.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 379I8KR035324514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Aug 2023 18:08:20 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6F0B5805E; Wed, 9 Aug 2023 18:08:19 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B258D58043; Wed, 9 Aug 2023 18:08:19 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.73.158]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 9 Aug 2023 18:08:19 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: joel@jms.id.au, linux-kernel@vger.kernel.org, alistair@popple.id.au, k@ozlabs.org, Eddie James Subject: [PATCH 2/2] fsi: Lock mutex for master device registration Date: Wed, 9 Aug 2023 13:08:14 -0500 Message-Id: <20230809180814.151984-3-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230809180814.151984-1-eajames@linux.ibm.com> References: <20230809180814.151984-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: SJKGVzOt3AZRUtcAJOd732wB2lZi7At6 X-Proofpoint-ORIG-GUID: SJKGVzOt3AZRUtcAJOd732wB2lZi7At6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-09_16,2023-08-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308090158 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773777780839905666 X-GMAIL-MSGID: 1773777780839905666 Because master device registration may cause hub master scans, or user scans may begin before device registration has ended, so the master scan lock must be held while registering the device. Signed-off-by: Eddie James --- drivers/fsi/fsi-core.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index c7a002076292..ad50cdaf8421 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -1306,7 +1306,6 @@ static struct class fsi_master_class = { int fsi_master_register(struct fsi_master *master) { int rc; - struct device_node *np; mutex_init(&master->scan_lock); @@ -1326,20 +1325,19 @@ int fsi_master_register(struct fsi_master *master) master->dev.class = &fsi_master_class; + mutex_lock(&master->scan_lock); rc = device_register(&master->dev); if (rc) { ida_free(&master_ida, master->idx); - return rc; - } + } else { + struct device_node *np = dev_of_node(&master->dev); - np = dev_of_node(&master->dev); - if (!of_property_read_bool(np, "no-scan-on-init")) { - mutex_lock(&master->scan_lock); - fsi_master_scan(master); - mutex_unlock(&master->scan_lock); + if (!of_property_read_bool(np, "no-scan-on-init")) + fsi_master_scan(master); } - return 0; + mutex_unlock(&master->scan_lock); + return rc; } EXPORT_SYMBOL_GPL(fsi_master_register);