Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp350940pxk; Thu, 3 Sep 2020 01:02:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkUvioQeGGpDinUdAwzsqd1ijdGaYyPhSRH8cB3lY5NTJObL+CBZlPuquGFaYC8Muj5Iyp X-Received: by 2002:a17:906:8695:: with SMTP id g21mr841241ejx.504.1599120159906; Thu, 03 Sep 2020 01:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599120159; cv=none; d=google.com; s=arc-20160816; b=TILtrAf/HGC0gwdZ1vOnob/Ly/cyITvDZ7aUhQuGSDiXfHepXoahuwry0K47G6dCbG 4hNU7FSyIl9delbOA7Alvfdob40qLPcZzmp6XYbxr7BDpaopU9pJJtidPR3DEVR0Ykm4 0h2C0rcIvyAvRhQSw9yMWFIdo4gVAXC/ADZoY0CJ9Hhi6cLb1M2E7NvPqNQBY1iEU74z Q+4SjW9+t2NejsJKbn4Ho9DMCyUl0p3hckyaKImx6XYwWOga+3vxQXthZ/DMSCaehula kt4SWEjffRdxBBRfkm0YAuhPOUWDhGbSmyR5O8JaBAh1I0VDYRF3FwlnXxFcSh1E747X Lz6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=631Dyyj+5J1i4PyIFclIjVjOc2aZH6fWRoROHrNThkE=; b=i1rNQmHC2KiS9usmbmr5Y7oZzMDeJhX4Nd3C25Bw57ITzJgIgqIGRM53td7BJylr1r KhVgzzGf8ha1kQv9c21CyiF8XvUpnEZ6OILY4W13vGCGkan10xjS3wvrC4jJ4fK8P8wm V41HfgBnNwJr6d6nZgt6YQcmqu1dCJGBlX/FydrVJ82JJTZU/rIIzPIhPVmDFEBF46cx ewU/tABmmXb20/nwEwN9kFM1R+F/6UAeQasZliR4tlamLFXMHdynP4ZZlvL8VqRc7cGL GYs51IojSg4sDEnuLjdwrwrXwR6zXukb3a+FCkMqlqVNc807eYYxGLYx6Scu0GktO+KU fz/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="OhuY/LJ9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bu14si1072648edb.128.2020.09.03.01.02.16; Thu, 03 Sep 2020 01:02:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="OhuY/LJ9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726047AbgICH7g (ORCPT + 99 others); Thu, 3 Sep 2020 03:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbgICH7b (ORCPT ); Thu, 3 Sep 2020 03:59:31 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5FFBC061244 for ; Thu, 3 Sep 2020 00:59:29 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id q13so2471626ejo.9 for ; Thu, 03 Sep 2020 00:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=631Dyyj+5J1i4PyIFclIjVjOc2aZH6fWRoROHrNThkE=; b=OhuY/LJ9ZXiJdh/h6zxSJ7jWF4WBeWwm7oxf2Bj21hgqvOBHdqyMY3NiFHrYE3jkzq cv2PJwXOQ+YuU+W/SvVq3zWMeX+Q+UL3Lb09KAdxxeDEG66pNKXz7svZrTC18ODLIF/m u5kI9UIUAkgJfs02/EvDhkayPfxIytG7rbkZzkjgcMDUFu8LqLYuMdWk3ewU967PVUBe 8QeRiXzsYZOYozH55E1xmt6INtDYVWVR3TEAY9jvqYURMIrq8Kcgbb7sCW6AqEts2mV9 5/BymYtNy1syz2I/scALDYE7FGXnK/tIKtOK2uHGP7L1HhtquFy+Qd9vOA1sr3nhfysG ngPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=631Dyyj+5J1i4PyIFclIjVjOc2aZH6fWRoROHrNThkE=; b=sP88qTVQeJ8pSmcym4dM1Darm/DLjVBIAr0sYpbg/0/QQatRs0untHNrjQLgJkkRAk BMzHhv4n/GpmPb04PwDZPU5KULM7Io7kGbxHtf6FoXSKdtqu2glnwKvmKrZe3cz1ElqU BAPXbjUU5yHAWOLuGAgGYdWA9PZXjxH2wPz3qmrkd3zZUWpEbyWYfMHc+EUi8fzsSn8m fm7yVy2iswU67tCnqnaO8Dn5dPyf1sfAJ3fiUtvEV5vbVnd+GKk76kJoPSINOxHbfgPk R3Tl2/xSn1lSVAGJoMAX9ull/3ysBULO2CMtaZkQAlZbSnHQmFi5RFlJ35VWJWAV7i5r oKkg== X-Gm-Message-State: AOAM532dMlUwS/IFb4cYW1ZNii+92+JOohAjbeYBwJHq0RMWeWZQmdHN RZ9jkbeUBcgWiDR+qfuK0Pc3c/vq8bOHa9i8sND4Jw== X-Received: by 2002:a17:906:d8ca:: with SMTP id re10mr852855ejb.382.1599119968510; Thu, 03 Sep 2020 00:59:28 -0700 (PDT) MIME-Version: 1.0 References: <20200831032006.1019978-1-warthog618@gmail.com> <20200831032006.1019978-12-warthog618@gmail.com> In-Reply-To: <20200831032006.1019978-12-warthog618@gmail.com> From: Bartosz Golaszewski Date: Thu, 3 Sep 2020 09:59:17 +0200 Message-ID: Subject: Re: [PATCH v6 11/20] gpiolib: cdev: support GPIO_V2_LINE_SET_VALUES_IOCTL To: Kent Gibson Cc: LKML , linux-gpio , Linus Walleij Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 31, 2020 at 5:23 AM Kent Gibson wrote: > > Add support for the GPIO_V2_LINE_SET_VALUES_IOCTL. > > Signed-off-by: Kent Gibson > --- > drivers/gpio/gpiolib-cdev.c | 59 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 59 insertions(+) > > diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c > index 936b8c9958dd..9f05bbd2161e 100644 > --- a/drivers/gpio/gpiolib-cdev.c > +++ b/drivers/gpio/gpiolib-cdev.c > @@ -777,6 +777,63 @@ static long linereq_get_values(struct linereq *lr, void __user *ip) > return 0; > } > > +static long linereq_set_values_unlocked(struct linereq *lr, > + struct gpio_v2_line_values *lv) > +{ > + DECLARE_BITMAP(vals, GPIO_V2_LINES_MAX); > + struct gpio_desc **descs; > + unsigned int i, didx, num_set; > + int ret; > + > + bitmap_zero(vals, GPIO_V2_LINES_MAX); > + for (num_set = 0, i = 0; i < lr->num_lines; i++) { > + if (lv->mask & BIT_ULL(i)) { > + if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags)) > + return -EPERM; > + if (lv->bits & BIT_ULL(i)) > + __set_bit(num_set, vals); > + num_set++; > + descs = &lr->lines[i].desc; > + } > + } > + if (num_set == 0) > + return -EINVAL; > + > + if (num_set != 1) { > + /* build compacted desc array and values */ > + descs = kmalloc_array(num_set, sizeof(*descs), GFP_KERNEL); Missing retval check. > + for (didx = 0, i = 0; i < lr->num_lines; i++) { > + if (lv->mask & BIT_ULL(i)) { > + descs[didx] = lr->lines[i].desc; > + didx++; > + } > + } > + } > + ret = gpiod_set_array_value_complex(false, true, num_set, > + descs, NULL, vals); > + > + if (num_set != 1) > + kfree(descs); > + return ret; > +} > + > +static long linereq_set_values(struct linereq *lr, void __user *ip) > +{ > + struct gpio_v2_line_values lv; > + int ret; > + > + if (copy_from_user(&lv, ip, sizeof(lv))) > + return -EFAULT; > + > + mutex_lock(&lr->config_mutex); > + > + ret = linereq_set_values_unlocked(lr, &lv); > + > + mutex_unlock(&lr->config_mutex); > + > + return ret; > +} > + > static long linereq_set_config_unlocked(struct linereq *lr, > struct gpio_v2_line_config *lc) > { > @@ -853,6 +910,8 @@ static long linereq_ioctl(struct file *file, unsigned int cmd, > > if (cmd == GPIO_V2_LINE_GET_VALUES_IOCTL) > return linereq_get_values(lr, ip); > + else if (cmd == GPIO_V2_LINE_SET_VALUES_IOCTL) > + return linereq_set_values(lr, ip); > else if (cmd == GPIO_V2_LINE_SET_CONFIG_IOCTL) > return linereq_set_config(lr, ip); > > -- > 2.28.0 >