From patchwork Tue Jul 18 16:24:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 9848881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B2FAB600CC for ; Tue, 18 Jul 2017 16:25:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5F101FF22 for ; Tue, 18 Jul 2017 16:25:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAA571FF82; Tue, 18 Jul 2017 16:25:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CE581FF22 for ; Tue, 18 Jul 2017 16:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751613AbdGRQZG (ORCPT ); Tue, 18 Jul 2017 12:25:06 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:60743 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751582AbdGRQZF (ORCPT ); Tue, 18 Jul 2017 12:25:05 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 18 Jul 2017 19:24:27 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v6IGORo0015439; Tue, 18 Jul 2017 19:24:27 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id v6IGOR8g023671; Tue, 18 Jul 2017 19:24:27 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id v6IGORNW023670; Tue, 18 Jul 2017 19:24:27 +0300 From: Yishai Hadas To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, yishaih@mellanox.com, maorg@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core] verbs: Avoid load drivers more than one time Date: Tue, 18 Jul 2017 19:24:09 +0300 Message-Id: <1500395049-23618-1-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Maor Gottlieb Drivers name list is built only once as part of read_config() and freed upon load_drivers(). As such, calling load_drivers() more than one time has no sense and might bring an oops in case there is some kernel driver without a matching user driver upon the second call. Fixes: c632072027a8 ('verbs: Refresh cahced ibv_device list') Signed-off-by: Maor Gottlieb Reviewed-by: Yishai Hadas --- Pull request was sent: https://github.com/linux-rdma/rdma-core/pull/169 libibverbs/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libibverbs/init.c b/libibverbs/init.c index b3046b3..1c41b36 100644 --- a/libibverbs/init.c +++ b/libibverbs/init.c @@ -495,6 +495,7 @@ int ibverbs_get_device_list(struct list_head *list) { struct ibv_sysfs_dev *tmp_sysfs_dev_list = NULL, *sysfs_dev, *next_dev; struct verbs_device *vdev, *tmp; + static int drivers_loaded; int num_devices = 0; int statically_linked = 0; int no_driver = 0; @@ -533,7 +534,7 @@ int ibverbs_get_device_list(struct list_head *list) no_driver = 1; } - if (!no_driver) + if (!no_driver || drivers_loaded) goto out; /* @@ -557,6 +558,7 @@ int ibverbs_get_device_list(struct list_head *list) } load_drivers(); + drivers_loaded = 1; for (sysfs_dev = tmp_sysfs_dev_list; sysfs_dev; sysfs_dev = sysfs_dev->next) {