Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp606002ybl; Wed, 4 Dec 2019 08:00:47 -0800 (PST) X-Google-Smtp-Source: APXvYqxOjc5NoKEolIjW6qfbqvLBtbWB49/2+fkE6FYyW79V4I9VXC3MlvajxL3sBBQIKmUvlmuq X-Received: by 2002:aca:1c0d:: with SMTP id c13mr3012861oic.44.1575475247382; Wed, 04 Dec 2019 08:00:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575475247; cv=none; d=google.com; s=arc-20160816; b=xu1p+bNXQDUXswTuG2OW/LAx4YdSbiQkysPgOteFr/DgXGjIOuzEKmjAS54u4d6ADL sGudaznUQrV5wCV/SZDym+CrIFf9YiHzhMRXqS2txnZyk20IOFn+b+nEssS40zxFJ3o5 jo4rS6H7hdB8pCxE202nMBMIjjLGgXmlekArXlg4uJe22qmFbUTSKVqhgP0CVtncP9Qs 8WLptkeLOgDZi3okq83/ZamIqPz6GfG9SIWKIBZ/URc4fA7W3LLlhlsLDndKCArlB3/R pGMEjWS6susWxSSD7c2ib5KOaLMCoKOR+NM4w0HDc+pX6rodyextu9JhGeHMn9YN0QfD OX3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UOWwdCy6TVkju/XVgGYrNAwqmnFLPpHnEAl2yx/CBt8=; b=GsyD2UhgNfwYBi2ZzGSnPsMWgrVmyKpqRFgJvNbx1tnBwHPFpyxfD7tsdSm9fk99IR TiWkSjkikCAUGCZE0/Ih+dhe4bthwVVQuKowDkpOvgSkWJhdoRXN/nhEb1/F7TZub2dj 6JWJDzmQMhTrXV2+Yav2JCZ0VzNpxWjoAmP/yjojgQeUY33pbvnEUEJd1rRnYhU134Gl B6/hUUpe2ezWuTXqJfySL3/20kRfWtf+3zEE6ePNbHFQJPlSekclzJWQf6z4w9VChO4I 8InX7FTefuWhD14PO4pvxoQieDKmNeg8ZFPEQ6ytKp1B462+i0GPj/XIVGnorgMkQ0T4 GPFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=X+uook1k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si1276450oig.45.2019.12.04.08.00.33; Wed, 04 Dec 2019 08:00:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=X+uook1k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728625AbfLDP7d (ORCPT + 99 others); Wed, 4 Dec 2019 10:59:33 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39810 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728608AbfLDP7c (ORCPT ); Wed, 4 Dec 2019 10:59:32 -0500 Received: by mail-wr1-f66.google.com with SMTP id y11so9227006wrt.6 for ; Wed, 04 Dec 2019 07:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UOWwdCy6TVkju/XVgGYrNAwqmnFLPpHnEAl2yx/CBt8=; b=X+uook1kRgRvmE3McO9/BVwAAZr04AoodqHjOIAmN5n2dNHYyv9wnrCFc7p4ZfwIUq aIftfQ1yxXnKD2DorRPeTA2RzHIg7M+efba4oCK6k8QdovXqUfPIwq9AJ2Qcs8h/38P1 Gb3TB4LynazhBAZfqLQitm3PilyB3+RxPvaZNs5PmTNpwaxAWxLT9Tz0Sv7q3jdT2JrL oA8c6D9J6F9wE4DAaC4/mcXHOBgKvTBV0uPpCsUHd6W3tCXuuZR0onSsA3vSQ3+aAgDP ABki0FN/bur1VoZtBz0Pou7Aijz60w1Sw0jkPp5WxVj2yH3ry+Qsrkk6WVwfFsBcXoK3 JQIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UOWwdCy6TVkju/XVgGYrNAwqmnFLPpHnEAl2yx/CBt8=; b=lZs/qVAMZId9V9kayYYu9JjnwHUBy8momXbDxNi7d+XmLXMXZJoHXtxrgwrgAOt6O+ xKu+q9Gs90ntoAlCiz7bxQ8nG36MOE4Plcb362MqzSx2wW8uCx5+Y/Dhkothm2bmrJ0F x4bmHGZVdONXdjC2JCTwXmoRArhEwC8P2obcGdh/bFNgXCiZz0pfETvXmlR3rPJVLZ+a FSnKD8dXHGV5c9SXBRh0vzAto+afemgMMt0U2mzUS32s2Ir0TPiM9EvpA7IXoPI/4/Iu j2lSdUYjC+UOzHDj50SQIo1WIAdf7c/pTkZceF5Zke7CL6KfC3qDEa9v/WYEq4WUyKXE oVdw== X-Gm-Message-State: APjAAAV3O/OArnEUaJ9fMQ1gv4GThuDhv2n9cZ9e5jWjUcnDWMA+gXUM cE3autMAzivQsNBDtchf4E+CKw== X-Received: by 2002:a05:6000:160d:: with SMTP id u13mr5041318wrb.22.1575475169910; Wed, 04 Dec 2019 07:59:29 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id u18sm8640508wrt.26.2019.12.04.07.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2019 07:59:28 -0800 (PST) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 09/11] gpiolib: provide a dedicated function for setting lineinfo Date: Wed, 4 Dec 2019 16:59:12 +0100 Message-Id: <20191204155912.17590-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204155912.17590-1-brgl@bgdev.pl> References: <20191204155912.17590-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski We'll soon be filling out the gpioline_info structure in multiple places. Add a separate function that given a gpio_desc sets all relevant fields. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 98 ++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c89d297da270..711963aa9239 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1145,6 +1145,60 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) return ret; } +static void gpio_desc_to_lineinfo(struct gpio_desc *desc, + struct gpioline_info *info) +{ + struct gpio_chip *chip = desc->gdev->chip; + unsigned long flags; + + spin_lock_irqsave(&gpio_lock, flags); + + if (desc->name) { + strncpy(info->name, desc->name, sizeof(info->name)); + info->name[sizeof(info->name) - 1] = '\0'; + } else { + info->name[0] = '\0'; + } + + if (desc->label) { + strncpy(info->consumer, desc->label, sizeof(info->consumer)); + info->consumer[sizeof(info->consumer) - 1] = '\0'; + } else { + info->consumer[0] = '\0'; + } + + /* + * Userspace only need to know that the kernel is using this GPIO so + * it can't use it. + */ + info->flags = 0; + if (test_bit(FLAG_REQUESTED, &desc->flags) || + test_bit(FLAG_IS_HOGGED, &desc->flags) || + test_bit(FLAG_USED_AS_IRQ, &desc->flags) || + test_bit(FLAG_EXPORT, &desc->flags) || + test_bit(FLAG_SYSFS, &desc->flags) || + !pinctrl_gpio_can_use_line(chip->base + info->line_offset)) + info->flags |= GPIOLINE_FLAG_KERNEL; + if (test_bit(FLAG_IS_OUT, &desc->flags)) + info->flags |= GPIOLINE_FLAG_IS_OUT; + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) + info->flags |= GPIOLINE_FLAG_ACTIVE_LOW; + if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) + info->flags |= (GPIOLINE_FLAG_OPEN_DRAIN | + GPIOLINE_FLAG_IS_OUT); + if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) + info->flags |= (GPIOLINE_FLAG_OPEN_SOURCE | + GPIOLINE_FLAG_IS_OUT); + if (test_bit(FLAG_BIAS_DISABLE, &desc->flags)) + info->flags |= GPIOLINE_FLAG_BIAS_DISABLE; + if (test_bit(FLAG_PULL_DOWN, &desc->flags)) + info->flags |= GPIOLINE_FLAG_BIAS_PULL_DOWN; + if (test_bit(FLAG_PULL_UP, &desc->flags)) + info->flags |= GPIOLINE_FLAG_BIAS_PULL_UP; + + spin_unlock_irqrestore(&gpio_lock, flags); +} + /* * gpio_ioctl() - ioctl handler for the GPIO chardev */ @@ -1185,49 +1239,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (IS_ERR(desc)) return PTR_ERR(desc); - if (desc->name) { - strncpy(lineinfo.name, desc->name, - sizeof(lineinfo.name)); - lineinfo.name[sizeof(lineinfo.name)-1] = '\0'; - } else { - lineinfo.name[0] = '\0'; - } - if (desc->label) { - strncpy(lineinfo.consumer, desc->label, - sizeof(lineinfo.consumer)); - lineinfo.consumer[sizeof(lineinfo.consumer)-1] = '\0'; - } else { - lineinfo.consumer[0] = '\0'; - } - - /* - * Userspace only need to know that the kernel is using - * this GPIO so it can't use it. - */ - lineinfo.flags = 0; - if (test_bit(FLAG_REQUESTED, &desc->flags) || - test_bit(FLAG_IS_HOGGED, &desc->flags) || - test_bit(FLAG_USED_AS_IRQ, &desc->flags) || - test_bit(FLAG_EXPORT, &desc->flags) || - test_bit(FLAG_SYSFS, &desc->flags) || - !pinctrl_gpio_can_use_line(chip->base + lineinfo.line_offset)) - lineinfo.flags |= GPIOLINE_FLAG_KERNEL; - if (test_bit(FLAG_IS_OUT, &desc->flags)) - lineinfo.flags |= GPIOLINE_FLAG_IS_OUT; - if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) - lineinfo.flags |= GPIOLINE_FLAG_ACTIVE_LOW; - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) - lineinfo.flags |= (GPIOLINE_FLAG_OPEN_DRAIN | - GPIOLINE_FLAG_IS_OUT); - if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) - lineinfo.flags |= (GPIOLINE_FLAG_OPEN_SOURCE | - GPIOLINE_FLAG_IS_OUT); - if (test_bit(FLAG_BIAS_DISABLE, &desc->flags)) - lineinfo.flags |= GPIOLINE_FLAG_BIAS_DISABLE; - if (test_bit(FLAG_PULL_DOWN, &desc->flags)) - lineinfo.flags |= GPIOLINE_FLAG_BIAS_PULL_DOWN; - if (test_bit(FLAG_PULL_UP, &desc->flags)) - lineinfo.flags |= GPIOLINE_FLAG_BIAS_PULL_UP; + gpio_desc_to_lineinfo(desc, &lineinfo); if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) return -EFAULT; -- 2.23.0