From patchwork Tue Feb 23 09:44:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 586788 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 10F24140B95 for ; Tue, 23 Feb 2016 20:45:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751015AbcBWJpI (ORCPT ); Tue, 23 Feb 2016 04:45:08 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:44850 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750758AbcBWJpH (ORCPT ); Tue, 23 Feb 2016 04:45:07 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1N9j1FS009103 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 23 Feb 2016 09:45:02 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1N9j1r6009055 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 23 Feb 2016 09:45:01 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u1N9j0xR006549; Tue, 23 Feb 2016 09:45:01 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 23 Feb 2016 01:45:00 -0800 Date: Tue, 23 Feb 2016 12:44:50 +0300 From: Dan Carpenter To: Linus Walleij Cc: Alexandre Courbot , linux-gpio@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] gpiolib: shifters used as flags in gpio_ioctl() Message-ID: <20160223094450.GB4030@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We weren't testing whether the bits were set correctly because we used shifters as flags. It means that we give the user incorrect line information in this new ioctl. Fixes: 521a2ad6f862 ('gpio: add userspace ABI for GPIO line information') Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b816469..d609e03 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -380,17 +380,19 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) * this GPIO so it can't use it. */ lineinfo.flags = 0; - if (desc->flags & (FLAG_REQUESTED | FLAG_IS_HOGGED | - FLAG_USED_AS_IRQ | FLAG_EXPORT | - FLAG_SYSFS)) + if (desc->flags & ((1 << FLAG_REQUESTED) | + (1 << FLAG_IS_HOGGED) | + (1 << FLAG_USED_AS_IRQ) | + (1 << FLAG_EXPORT) | + (1 << FLAG_SYSFS))) lineinfo.flags |= GPIOLINE_FLAG_KERNEL; - if (desc->flags & FLAG_IS_OUT) + if (test_bit(FLAG_IS_OUT, &desc->flags)) lineinfo.flags |= GPIOLINE_FLAG_IS_OUT; - if (desc->flags & FLAG_ACTIVE_LOW) + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) lineinfo.flags |= GPIOLINE_FLAG_ACTIVE_LOW; - if (desc->flags & FLAG_OPEN_DRAIN) + if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) lineinfo.flags |= GPIOLINE_FLAG_OPEN_DRAIN; - if (desc->flags & FLAG_OPEN_SOURCE) + if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) lineinfo.flags |= GPIOLINE_FLAG_OPEN_SOURCE; if (copy_to_user(ip, &lineinfo, sizeof(lineinfo)))