From patchwork Wed Sep 9 17:21:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 7147621 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ECF2BBEEC1 for ; Wed, 9 Sep 2015 17:17:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 00B7C20A13 for ; Wed, 9 Sep 2015 17:17:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1712420567 for ; Wed, 9 Sep 2015 17:17:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0919F6EC8D; Wed, 9 Sep 2015 10:17:27 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by gabe.freedesktop.org (Postfix) with ESMTPS id A97206EC08 for ; Wed, 9 Sep 2015 10:17:25 -0700 (PDT) Received: by wicfx3 with SMTP id fx3so165061324wic.1 for ; Wed, 09 Sep 2015 10:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7vnbXpo0yWCpBNRxQLFKYGQ75FDDTn50V1gZJa66iG4=; b=OMMZ0zNFI5fc+UU5QIUjgNZxs8mlp5AG0V0TObNJLXXKJr03D+MRaus0sy3ZBMW5jd MYaHguknpsKNlDgZHkxxrutujvYGDm4mESSkHNfqffdC6q4yxNzqozmJMelZEinlze/h Fptg0L32Y9SevVIeuObfKEKf0g7C60LmCev/YkN3YhYqhKMS04XyBuUdABoOUlNaRW8U gwON/htZLqg+edAnEOBrqUcUbxG/LkkJ4mstK5E7iAHoiVvZuZdtoodc2mGA9TKF/Bu5 PBFa15biZCDLk+xT70UVJgwwSVOB5l7B6alB9xt24ZLrPQ2UPg3h2UjWKjyWpVteQ+7Z ieOQ== X-Received: by 10.180.85.104 with SMTP id g8mr47348265wiz.57.1441819044170; Wed, 09 Sep 2015 10:17:24 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by smtp.gmail.com with ESMTPSA id j7sm11257042wjz.11.2015.09.09.10.17.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 10:17:23 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 03/12] xf86drm: move platform details to drmParsePciDeviceInfo() Date: Wed, 9 Sep 2015 18:21:24 +0100 Message-Id: <1441819293-25567-4-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> References: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> Cc: emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As with previous commit let's try to keep drmGetDevices clean of linux specifics. Signed-off-by: Emil Velikov --- xf86drm.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index b4c5aa0..1174a64 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2924,11 +2924,22 @@ static int drmGetNodeType(const char *name) return -EINVAL; } -static int drmParsePciDeviceInfo(const unsigned char *config, +static int drmParsePciDeviceInfo(const char *d_name, drmPciDeviceInfoPtr device) { - if (config == NULL) - return -EINVAL; + char path[PATH_MAX + 1]; + unsigned char config[64]; + int fd, ret; + + snprintf(path, PATH_MAX, "/sys/class/drm/%s/device/config", d_name); + fd = open(path, O_RDONLY); + if (fd < 0) + return -errno; + + ret = read(fd, config, sizeof(config)); + close(fd); + if (ret < 0) + return -errno; device->vendor_id = config[0] | (config[1] << 8); device->device_id = config[2] | (config[3] << 8); @@ -2991,10 +3002,8 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) struct stat sbuf = {0}; char node[PATH_MAX + 1] = ""; char path[PATH_MAX + 1] = ""; - unsigned char config[64] = ""; int node_type, subsystem_type; int maj, min; - int fd; int ret, i = 0, j, node_count, device_count = 0; int max_count = 16; int *duplicated = NULL; @@ -3063,32 +3072,17 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) devs[i].available_nodes = 1 << node_type; if (devices != NULL) { - snprintf(path, PATH_MAX, "/sys/class/drm/%s/device/config", - dent->d_name); - fd = open(path, O_RDONLY); - if (fd < 0) { - ret = -errno; - goto free_locals; - } - ret = read(fd, config, 64); - if (ret < 0) { - ret = -errno; - close(fd); - goto free_locals; - } - pcidevice = calloc(1, sizeof(*pcidevice)); if (pcidevice == NULL) { ret = -ENOMEM; goto free_locals; } - ret = drmParsePciDeviceInfo(config, pcidevice); + ret = drmParsePciDeviceInfo(dent->d_name, pcidevice); if (ret) goto free_locals; devs[i].deviceinfo.pci = pcidevice; - close(fd); } break; default: