From patchwork Wed Sep 5 12:31:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Engestrom X-Patchwork-Id: 10588839 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AEE4920 for ; Wed, 5 Sep 2018 12:32:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26C6329C89 for ; Wed, 5 Sep 2018 12:32:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 192F729CC7; Wed, 5 Sep 2018 12:32:01 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0FA6629C89 for ; Wed, 5 Sep 2018 12:31:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D90EE6E127; Wed, 5 Sep 2018 12:31:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id DBA1C6E127 for ; Wed, 5 Sep 2018 12:31:55 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Sep 2018 05:31:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,333,1531810800"; d="scan'208";a="87388548" Received: from dfava-mobl.ger.corp.intel.com (HELO eengestr-dev.ger.corp.intel.com) ([10.252.9.73]) by fmsmga001.fm.intel.com with ESMTP; 05 Sep 2018 05:31:54 -0700 From: Eric Engestrom To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 1/2] xf86drm: merge get_normal_pci_path() into get_real_pci_path() Date: Wed, 5 Sep 2018 13:31:48 +0100 Message-Id: <20180905123149.18117-1-eric.engestrom@intel.com> X-Mailer: git-send-email 2.18.0 Organization: Intel Corp UK X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emil Velikov MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Cc: Emil Velikov Signed-off-by: Eric Engestrom Reviewed-by: Emil Velikov --- xf86drm.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 7807dce9c7fbba6d74f7..649d400bcbc494ac04e6 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2998,26 +2998,20 @@ static int drmParseSubsystemType(int maj, int min) #endif } -static char * +static void get_real_pci_path(int maj, int min, char *real_path) { char path[PATH_MAX + 1], *term; snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min); - if (!realpath(path, real_path)) - return NULL; + if (!realpath(path, real_path)) { + strcpy(real_path, path); + return; + } term = strrchr(real_path, '/'); if (term && strncmp(term, "/virtio", 7) == 0) *term = 0; - - return real_path; -} - -static void -get_normal_pci_path(int maj, int min, char *normal_path) -{ - snprintf(normal_path, PATH_MAX, "/sys/dev/char/%d:%d/device", maj, min); } static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info) @@ -3027,8 +3021,7 @@ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info) char real_path[PATH_MAX + 1], *value; int num; - if (get_real_pci_path(maj, min, real_path) == NULL) - get_normal_pci_path(maj, min, real_path); + get_real_pci_path(maj, min, real_path); value = sysfs_uevent_get(real_path, "PCI_SLOT_NAME"); if (!value) @@ -3148,8 +3141,7 @@ static int parse_separate_sysfs_files(int maj, int min, FILE *fp; int ret; - if (get_real_pci_path(maj, min, real_path) == NULL) - get_normal_pci_path(maj, min, real_path); + get_real_pci_path(maj, min, real_path); for (unsigned i = ignore_revision ? 1 : 0; i < ARRAY_SIZE(attrs); i++) { snprintf(path, PATH_MAX, "%s/%s", real_path, attrs[i]); @@ -3180,8 +3172,7 @@ static int parse_config_sysfs_file(int maj, int min, unsigned char config[64]; int fd, ret; - if (get_real_pci_path(maj, min, real_path) == NULL) - get_normal_pci_path(maj, min, real_path); + get_real_pci_path(maj, min, real_path); snprintf(path, PATH_MAX, "%s/config", real_path); fd = open(path, O_RDONLY);