Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp3180256ybh; Sat, 25 Jul 2020 13:58:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBPvrNNEKplnY03E2evsDv5lzyN+CXOKdSxZn6Dp9k8ENz80JCeWAmuMTDNvDC3qWao1md X-Received: by 2002:a17:906:1704:: with SMTP id c4mr15357810eje.525.1595710720073; Sat, 25 Jul 2020 13:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595710720; cv=none; d=google.com; s=arc-20160816; b=BmM9nhvtUA3OiEum4l6Bmelb36YPwpfJOU9VMVD3K6WnFjoORuNmkrw7uWbTZt72Cp 5jM+UVkMl1Ojaa4B5tUdHyIvWESr4IPL1akyCMa2PY9ZT6bwgfMG1Adqd3ymjBZ7Tnnz Y1JqmhflVLbdE8OdLt2Ln0+IQuXshLP7MvykpWGFZmPjTufk5GMxVehQ03qjfB+kj2+I 9d34bvMFiwWA8KSS0vDnY2BTBii7JBIAXhMxodfABi1g5cDBp6JyCSOT9Q7T0BBzUQrH c9axUrSFz9nVZYxm+GleRtp41atoNVOLarkC7KNCCHdhdVIntnKJm3o7OYGmf5bFWDXn aGKw== 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=Hhs+1xM7FhyybbR0iXVsCSFCjTnqQqQ71jqS9xdAn3Y=; b=SednlheWiVky4EPftsCCup8RohnfVJ9mQN/Ex4WtlxhpNKfAWfUDVfGnUPB1HwQxsp q6kH51IuZxf98m7x5rCHzuOu0Qo1vVcAJewo28zhESnIjgqvRT0JdYp6W22pUhhbPscG lN2rmgtn66ukYjs80TNh2TRcNJ8wGImMZw6zzsZh5U/GkQBaZQ+xX0zeiCxuOgAhe7Ss 0pUbpD4l+VgKSIG4ptHXQEvB0Dtey1bpDZ/ijtGbGUDo1Ia7FdCENPkNnbdFZEEDauau NTO7ILll0mb1BAAuc++MbyRGKdiqPoFl9Qb0+FSVgKWlvIXDoCaVrs8lALFz7p4Yvx5C Ij9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IPRH08HK; 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 e12si3308407edc.318.2020.07.25.13.58.17; Sat, 25 Jul 2020 13:58:40 -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=IPRH08HK; 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 S1727983AbgGYUwN (ORCPT + 99 others); Sat, 25 Jul 2020 16:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726893AbgGYUwM (ORCPT ); Sat, 25 Jul 2020 16:52:12 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98E9CC08C5C0; Sat, 25 Jul 2020 13:52:11 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id m16so6220855pls.5; Sat, 25 Jul 2020 13:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hhs+1xM7FhyybbR0iXVsCSFCjTnqQqQ71jqS9xdAn3Y=; b=IPRH08HKCRZ88hk4TmoW2iHRPZN33mH1aL4FzajE0Nohrf0HwdaOi9MDoFZCAcpPCM ZlGvT0ffQpDcD23LL/tB1jsChRCoQarOw+00bSBKIxX02d0VUmqLVySh1LgRh+WAA0ZK kV5qd8GZVmhRhBQlxPTe0Uec7tMhKyDyJJqHH9JKDYNKR2+NDxfsrVPSIOWIfip/ddF2 rUhz6JmMGyCF5K71HJo6O1FvBU4Ve0/++KyR+WjD+G87KMXF1chWsvyR9iQgV6LNXh4i c3qHniK+vvCgc9PxBMksKf9Yk6puB+NphBCyq5+coXHs/3O2IPMndYUgz9n5e2cgv+JF qrhA== 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=Hhs+1xM7FhyybbR0iXVsCSFCjTnqQqQ71jqS9xdAn3Y=; b=p63zmhVweZ6eH8880Sq8B8FxVbxxRN4NbKeqVpGdAaTRoB78NlkGylRhZm5NwhH4XI cMAtneCmfLHSPMDyIcNPiH/W/aLi5fKrjtmD8aLX61ls9A6HORh/hfWtciGeL9u1naKJ MBBpXklDf9Q9TJ7tboJbWhL5zXJUxM61julZ8eh7W7f5g2Vm/RglGiieRXfrK+HHgSiu M3Q1tqeZTIEpz+9VD4mRQKmhE0MNLb82ZVkh+7InCM76muKmbnBowOSp9KjGhnzjyB4F TL+gScZWcV47mH34B29zn6FLCk3od5nmtMGEJi/68Gv5LfyUXiJBx+sKSZj9HMbQS5uu mZfA== X-Gm-Message-State: AOAM530dfKdpUMDPjFVUlKFmZSZUJRVkPrdq+bFFOLi9qLwlEKaBm9N+ sulSfZx1F8UaFNtbX5a9Z7Ja9ippC/mSSViCsNE= X-Received: by 2002:a17:90b:3547:: with SMTP id lt7mr11307651pjb.181.1595710330583; Sat, 25 Jul 2020 13:52:10 -0700 (PDT) MIME-Version: 1.0 References: <20200725041955.9985-1-warthog618@gmail.com> <20200725041955.9985-6-warthog618@gmail.com> In-Reply-To: <20200725041955.9985-6-warthog618@gmail.com> From: Andy Shevchenko Date: Sat, 25 Jul 2020 23:51:54 +0300 Message-ID: Subject: Re: [PATCH v2 05/18] gpiolib: cdev: support GPIO_GET_LINE_IOCTL and GPIOLINE_GET_VALUES_IOCTL To: Kent Gibson Cc: Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , 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 Sat, Jul 25, 2020 at 7:24 AM Kent Gibson wrote: > > Add support for requesting lines using the GPIO_GET_LINE_IOCTL, and > returning their current values using GPIOLINE_GET_VALUES_IOCTL. ... > +struct line { > + struct gpio_device *gdev; > + const char *label; > + u32 num_descs; > + /* descs must be last so it can be dynamically sized */ I guess [] implies above comment and thus comment can be dropped. > + struct gpio_desc *descs[]; > +}; ... > +static bool padding_not_zeroed(__u32 *padding, int pad_size) > +{ > + int i, sum = 0; > + > + for (i = 0; i < pad_size; i++) > + sum |= padding[i]; > + > + return sum; > +} Reimplementation of memchr_inv() ? ... > +static u64 gpioline_config_flags(struct gpioline_config *lc, int line_idx) > +{ > + int i; > + > + for (i = lc->num_attrs - 1; i >= 0; i--) { Much better to read is unsigned int i = lc->num_attrs; while (i--) { ... } > + if ((lc->attrs[i].attr.id == GPIOLINE_ATTR_ID_FLAGS) && > + test_bit(line_idx, (unsigned long *)lc->attrs[i].mask)) This casting is not good. What about BE 32-bit architecture? > + return lc->attrs[i].attr.flags; > + } > + return lc->flags; > +} > + > +static int gpioline_config_output_value(struct gpioline_config *lc, > + int line_idx) > +{ Same comments as per above. > +} ... > +static long line_get_values(struct line *line, void __user *ip) > +{ > + struct gpioline_values lv; > + unsigned long *vals = (unsigned long *)lv.bits; Casting u64 to unsigned long is not good. > +} ... > +static void line_free(struct line *line) > +{ > + int i; > + > + for (i = 0; i < line->num_descs; i++) { > + if (line->descs[i]) Redundant? > + gpiod_free(line->descs[i]); > + } > + kfree(line->label); > + put_device(&line->gdev->dev); > + kfree(line); > +} ... > + /* Make sure this is terminated */ > + linereq.consumer[sizeof(linereq.consumer)-1] = '\0'; > + if (strlen(linereq.consumer)) { > + line->label = kstrdup(linereq.consumer, GFP_KERNEL); kstrndup() ? > + if (!line->label) { > + ret = -ENOMEM; > + goto out_free_line; > + } > + } ... > + struct gpio_desc *desc = gpiochip_get_desc(gdev->chip, offset); I prefer to see this split, but it's minor. > + if (IS_ERR(desc)) { > + ret = PTR_ERR(desc); > + goto out_free_line; > + } ... > + dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", > + offset); Perhaps tracepoint / event? -- With Best Regards, Andy Shevchenko