Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2440430pxk; Sun, 20 Sep 2020 04:15:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztHE0oQgjM5l1ZvnJLzFTqMBdG5hDK+1J4s26DSMMKWQZb74NwbXYdsz9nbDRe6uICWqCs X-Received: by 2002:a17:906:4754:: with SMTP id j20mr46278319ejs.293.1600600553160; Sun, 20 Sep 2020 04:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600600553; cv=none; d=google.com; s=arc-20160816; b=n6GpFXjYZK335VlaivYB8TyuKk7vJ/i3k8igJDLRqTKgt18uBs7EAdQSGdkBi0l6oj nEJctE4cNrBmM4QGUI+kuvLlPCSobID4vf0NFfUJcq8dJE7mssSEo4Kd8klBysMhItbN 4w+VCxHlbmUvKEIhvHN9ojYKTDoVdS4pzx+rcaFtYtTQsdVQzyUGiJ8j3sqP6Yk7HgXV KtgdaAz8ruP8/vOkvqlLq4KL/BphGK8qQklhQrfhmscFGndPWjqoSUZtD61tMq3gGoGV YF6xuBlbQTvYvklZD66/rIqWBfylvdFGV3VEjzoy5oxjLwbRKDeBghRvtz/7Sm4ugliV UZAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SK3azXNEl6yyJpFq5d1iG5zYYrlyno7Q8Ly4/yE9BOw=; b=1Bbk4Xv8X8ZXiYVsBbxgoEeWsAjG7uquDcxDZZLQ4qSZqrS564ke3fFk5Ga+me1rLe hdcKcqkai7jjm2k8Le6FEHdhXARI0PCAgRDbWhcO69Mq21nILYKbSKqzZhb0jl+YNi0J Vht6y1qcX9yokmMT+V6xgHnWjQdV/dJanm8kaaZU5WgxMuqvstszsH9SEhnjcVnz1X5U OxZu2WqoRqkf4ZNQKdDsMp5i/gDhaaf779M1hInr8mWwE87jPatS8N4F5d/oIKEhi8d7 exkuepq0wALBrcgcCfgYUnaFn/JDiDYFyX2i4Uc/WzvWZS74ghdZ93ILXXHF6XceRsgk D86w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=n6+rQwSl; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id re10si3181391ejb.57.2020.09.20.04.15.29; Sun, 20 Sep 2020 04:15:53 -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=@gmail.com header.s=20161025 header.b=n6+rQwSl; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726344AbgITLML (ORCPT + 99 others); Sun, 20 Sep 2020 07:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbgITLMK (ORCPT ); Sun, 20 Sep 2020 07:12:10 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99A16C061755; Sun, 20 Sep 2020 04:12:10 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id t7so5695094pjd.3; Sun, 20 Sep 2020 04:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=SK3azXNEl6yyJpFq5d1iG5zYYrlyno7Q8Ly4/yE9BOw=; b=n6+rQwSl1SrCYFdOOctb8jo002SA1KxyLmOokDezLuQi+zK4b9DqigFXhppot6OT6U FzkYUI8U4gUr2QCMDpKZxrbtU67rOmxWoWN4bkk7hiR5h9mhB4xDeLkqkOlXLHwd7SUv 37z3mreIRiM2OGDTAcZ5Vmdur61iTwrpCnpJnIIsxXajBGH1m1Ts4FLbpPXipaz/sVvk 3nUOwfx2aOYTksA1tzaNhY7phJnfuKL3xIE2K6Wgp+Eibe3qUKljivBSxdedUIYb2CtL UeYMWF3ibd1Iv2pULnKqMqrK/zuLOo72imdf5kXZSuaeXZStxRV37yHMZtqFjKv4lVAN i5Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=SK3azXNEl6yyJpFq5d1iG5zYYrlyno7Q8Ly4/yE9BOw=; b=t5EwD+A8vY546ObXZJzAgN+gKQLmakY3RKYG+PJfEivF0DT0Ibtsf49fr0I9gSB4Io DY/aWMKSNES+R1yq09t6fvB3CsQCsuecox7q381zQvNfMFee3g0rDXzL7anSGzgEUsGT YKCaOGeKQfR08kVnetMYawZuy55yqfqDsj2K35tBDEjug9cNvGBAh+lO+EFgufuuyqAW fc+B6fPoegf06ooLwjHyBrSof0BKDkh0dwgOlN46DR/p1T/uEeNOgNNHeJpwXieQ2rUL 5Y0d5Nhp7nId8YY8nAnYRNUpJIhVuhO2GfP30CLUsb9GlIkV6t0COAjOKhe/vpLYykNW OXRA== X-Gm-Message-State: AOAM531YSayh8/mWe1Lv6tG1RuxkBriGZ2lvMd5BYFKJ0dUiK5lug0LI dU7eK/kQI++HMPIL35V5lZCm7yWdtDA= X-Received: by 2002:a17:90a:c83:: with SMTP id v3mr20130659pja.229.1600600329910; Sun, 20 Sep 2020 04:12:09 -0700 (PDT) Received: from sol (106-69-189-59.dyn.iinet.net.au. [106.69.189.59]) by smtp.gmail.com with ESMTPSA id j13sm5469374pjn.14.2020.09.20.04.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:12:09 -0700 (PDT) Date: Sun, 20 Sep 2020 19:12:04 +0800 From: Kent Gibson To: Andy Shevchenko Cc: Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Linus Walleij Subject: Re: [PATCH v7 07/20] gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL Message-ID: <20200920111204.GB793608@sol> References: <20200905133549.24606-1-warthog618@gmail.com> <20200905133549.24606-8-warthog618@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15, 2020 at 01:31:27PM +0300, Andy Shevchenko wrote: > On Sat, Sep 5, 2020 at 4:49 PM Kent Gibson wrote: > > > > Add support for requesting lines using the GPIO_V2_GET_LINE_IOCTL, and > > returning their current values using GPIO_V2_LINE_GET_VALUES_IOCTL. > > > > The struct linereq implementation is based on the v1 struct linehandle > > implementation. > > > > Signed-off-by: Kent Gibson > > --- > > [snip] > > > + /* Bias requires explicit direction. */ > > + if ((flags & GPIO_V2_LINE_BIAS_FLAGS) && > > + !(flags & GPIO_V2_LINE_DIRECTION_FLAGS)) > > + return -EINVAL; > > Why is this? If I request a line as is and after set a bias, should I > really care about direction? > Yeah, you probably should be aware of the direction if they are setting the bias, so this makes sure they are. The practical reason is that gpiod_direction_output() or gpiod_direction_input() have to be called to set the bias, and they are only called if the corresponding flag is set. > > > + for (num_get = 0, i = 0; i < lr->num_lines; i++) { > > + if (lv.mask & BIT_ULL(i)) { > > for_each_set_bit() ? > No - lv.mask is u64, not unsigned long. You could do a cast, but it would break on BE-32. Sound familar? - you caught me doing just that in your review of an earlier version. > > + ulr.consumer[sizeof(ulr.consumer)-1] = '\0'; > > + if (strlen(ulr.consumer)) { > > + lr->label = kstrdup(ulr.consumer, GFP_KERNEL); > > Sounds like kstrndup() > Been here before too - they differ slightly in that here lr->label is left null if consumer is empty, whereas kstrndup() would alloc one byte just for the null terminator. > > + } > > + > > + blocking_notifier_call_chain(&desc->gdev->notifier, > > + GPIOLINE_CHANGED_REQUESTED, desc); > > + > > > + dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", > > + offset); > > Hmm... I would rather see trace events / points than new dev_dbg() / > pr_debug() calls. > Agreed - it is on the TODO list. I have looked at it and doing it properly would mean adding tracepoints to gpiolib.c, and modifying the v1 code as well, so it is best done in a separate patch later... > > @@ -1104,6 +1505,25 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) > > MAJOR(devt), gdev->id); > > > > return 0; > > + /* > > + * array sizes must ensure 64-bit alignment and not create holes in > > + * the struct packing. > > + */ > > + BUILD_BUG_ON(IS_ALIGNED(GPIO_V2_LINES_MAX, 2)); > > + BUILD_BUG_ON(IS_ALIGNED(GPIO_MAX_NAME_SIZE, 8)); > > + > > + /* > > + * check that uAPI structs are 64-bit aligned for 32/64-bit > > + * compatibility > > + */ > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_attribute), 8)); > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_config_attribute), 8)); > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_config), 8)); > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_request), 8)); > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_info), 8)); > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_info_changed), 8)); > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_event), 8)); > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_values), 8)); > > Can we use static_assert() at the top of the file? Presumably after > inclusion block. > Good idea - will do. Cheers, Kent.