Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp155316pxb; Wed, 3 Feb 2021 02:05:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyA9CL1PjVNp1PrX0iSOjK7IMoxv7nCXhe1l5+BwFnmJMQBIB8RsADL0vYg9yHgxb+ktvPN X-Received: by 2002:a17:906:408b:: with SMTP id u11mr2342971ejj.299.1612346756347; Wed, 03 Feb 2021 02:05:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612346756; cv=none; d=google.com; s=arc-20160816; b=W4OD5dAQ47rKCsPYhy1le1jzED0AU4IXwYvoVylT8NwH4rRg3j7uhzP3d+KBJubWdT d+CqrePEQDl/UQxXYEU5q167H/QrsqSKMxg93p9L1qQ1huzO/HOFQbmxfRPUWo0zmaf3 k/wxl7ydthAQ39vReNWOg3YNNOqrqKx56A2+MgwMOAijp+OouvqFnhgjz8dAeIlPs5Eq tUhNTg+KDFyY0mQAgsk5ALTps69IYdySRhPxtIKQ64Eowm+bBJVj8ivvK5aEIg/m4Qz1 +O3VOaSWevzI92ohPE7iMPAHsyoSQW2gJOfp6zja425eOP2iYS2lqLUkbFA+rmMypJgo RlTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=J2oISiYeGVu9ZpGUGgNNH2LGtwu+nmXL1dEBI84TFMM=; b=MoUXsSC+dFLPe/oLHF3DTUlOTu/Az083I0H0ys7Nu13zzES2HdcLETv/I74pEi9A0t QTtZbaWVFRiHhojaHLpexk0mHF4/bXHv39/jT5MUR14hmVaLoAPe4t4q6S5PwxdeYM2t DIS5Co0FxNp1sZ82TBfv6hq2WhBJViUCxHa1PhVaNF4VUkFGHX5rRm45MowX1OAkIYC3 lN+68gJkYd3gLKLLyIwAwGVcK562lvLYYDNSmbgivaSVQMKmJOYqSYznY4W0DweZ6FlE QVADQcD0uiT1gQace7VJEAfvDo/QUaAkQYLe/ReRJ0sfu8fjSeP7WvtBmmrhKwavx36H FDqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=W+1GldZs; 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 cm20si812321edb.371.2021.02.03.02.05.23; Wed, 03 Feb 2021 02:05:56 -0800 (PST) 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=W+1GldZs; 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 S233758AbhBCKC7 (ORCPT + 99 others); Wed, 3 Feb 2021 05:02:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233622AbhBCKC5 (ORCPT ); Wed, 3 Feb 2021 05:02:57 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B06D1C061573; Wed, 3 Feb 2021 02:02:17 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id s23so15712772pgh.11; Wed, 03 Feb 2021 02:02:17 -0800 (PST) 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=J2oISiYeGVu9ZpGUGgNNH2LGtwu+nmXL1dEBI84TFMM=; b=W+1GldZsRoSu3m/0ipd3CCiVm4f8is+x3pSwGQwqTXOG0nRj0cLxX2xW4EbF6qJrfd CAZdVXqimcETYd0G5B1J3IqfqENiCQsxGU/NdovEJX2rr5881ffBLMRy3grwkLnjMlwg 1SZnp4oC/GGmhU4KDvA8sYzapKZPC4XeBTzRbq5C9CVzeuyaeMRYPkXdKaN19pEIzAz0 Oax4tmJ9475sK1JLvaCcgyTu70CuExP7CP1IT1L+2BSQeaYxZ9QvrUwSwgY6WB6N6g58 Pe0er4Jbdv08inotyKuuUXJf0XclpttapQvN0GdUqdkrPAmihgRw4VqQl4K8MiatyepO cXnw== 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=J2oISiYeGVu9ZpGUGgNNH2LGtwu+nmXL1dEBI84TFMM=; b=pbvyFTI0WxqX3zAmZm/GDSBMTsalg4pcS9gFeW0eWqLuBv0+QYjcQao/0UqOOfT9Ul X1VnPmSP7O+/CvmRgfeUWqKM5goOsnsuQaaph4ZVaKqbzCg7x1J7W+frv5phxjbUXAVt OTKXyukht6f6liFIiiXAENLA7ag0P7zjoTUXQwKO1lfVdWBwC8i4BnCSz/LPuXsW8L3q 6QcUhqrHWHhfX7ZfrSdHBuz+TjLiHN6ZBlET7HeGlkZoaeyrtRmkRlThnuDLwXTVtkIk KjzGcLbDJeGQsasN5EY6P2XxzX+KwyWOCYoD2OElKxza4f7WcATDQbiKVSdhRPaFE+VY UKOw== X-Gm-Message-State: AOAM531E7V5I65rFEoJle2t+pV+MGZI3DNHDipInMgQ3z3tJiNy6vHZD Xgx3tvE75jB/5JwcuJlJjcJZrqRE/Uheu0iUDlw0Q1N600FAYw== X-Received: by 2002:a65:644b:: with SMTP id s11mr2839544pgv.4.1612346537161; Wed, 03 Feb 2021 02:02:17 -0800 (PST) MIME-Version: 1.0 References: <20210201145105.20459-1-alexandru.ardelean@analog.com> <20210201145105.20459-7-alexandru.ardelean@analog.com> In-Reply-To: <20210201145105.20459-7-alexandru.ardelean@analog.com> From: Andy Shevchenko Date: Wed, 3 Feb 2021 12:02:00 +0200 Message-ID: Subject: Re: [PATCH v3 06/11] iio: core: merge buffer/ & scan_elements/ attributes To: Alexandru Ardelean Cc: Linux Kernel Mailing List , linux-iio , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , =?UTF-8?B?TnVubyBTw6E=?= , "Bogdan, Dragos" , "Rafael J. Wysocki" , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 1, 2021 at 5:28 PM Alexandru Ardelean wrote: > > With this change, we create a new directory for the IIO device called > buffer0, under which both the old buffer/ and scan_elements/ are stored. > > This is done to simplify the addition of multiple IIO buffers per IIO > device. Otherwise we would need to add a bufferX/ and scan_elementsX/ > directory for each IIO buffer. > With the current way of storing attribute groups, we can't have directories > stored under each other (i.e. scan_elements/ under buffer/), so the best > approach moving forward is to merge their attributes. > > The old/legacy buffer/ & scan_elements/ groups are not stored on the opaque > IIO device object. This way the IIO buffer can have just a single > attribute_group object, saving a bit of memory when adding multiple IIO > buffers. ... > +static int iio_buffer_register_legacy_sysfs_groups(struct iio_dev *indio_dev, > + struct attribute **buffer_attrs, > + int buffer_attrcount, > + int scan_el_attrcount) > +{ > + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); > + struct attribute_group *group; > + int ret; > + > + group = &iio_dev_opaque->legacy_buffer_group; > + group->attrs = kcalloc(buffer_attrcount + 1, > + sizeof(struct attribute *), GFP_KERNEL); > + if (!group->attrs) > + return -ENOMEM; > + > + memcpy(group->attrs, buffer_attrs, > + buffer_attrcount * sizeof(struct attribute *)); kmemdup() ? Perhaps introduce kmemdup_array(). > + group->name = "buffer"; > + > + ret = iio_device_register_sysfs_group(indio_dev, group); > + if (ret) > + goto error_free_buffer_attrs; > + > + group = &iio_dev_opaque->legacy_scan_el_group; > + group->attrs = kcalloc(scan_el_attrcount + 1, > + sizeof(struct attribute *), GFP_KERNEL); > + if (!group->attrs) { > + ret = -ENOMEM; > + goto error_free_buffer_attrs; > + } > + > + memcpy(group->attrs, &buffer_attrs[buffer_attrcount], > + scan_el_attrcount * sizeof(struct attribute *)); Ditto. > + group->name = "scan_elements"; > + > + ret = iio_device_register_sysfs_group(indio_dev, group); > + if (ret) > + goto error_free_scan_el_attrs; > + > + return 0; > + > +error_free_buffer_attrs: > + kfree(iio_dev_opaque->legacy_buffer_group.attrs); > +error_free_scan_el_attrs: > + kfree(iio_dev_opaque->legacy_scan_el_group.attrs); > + > + return ret; > +} -- With Best Regards, Andy Shevchenko