Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp349888rwd; Wed, 7 Jun 2023 00:23:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dOGr4uKjOZaCEpy7Ub7Dwaq3bmTZjoZ4Ed6s2GxgotYSqzTwiG1mQr8M7fomzpUqyjDGo X-Received: by 2002:a17:90a:6c23:b0:24b:4e7b:c689 with SMTP id x32-20020a17090a6c2300b0024b4e7bc689mr1699261pjj.35.1686122585067; Wed, 07 Jun 2023 00:23:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686122585; cv=none; d=google.com; s=arc-20160816; b=a1DlOzBFrVfkGVGPBDFaEaTnt4fYPRJztSXDzcMMPzh6RrtfA2MdBgSQcWnhrCKg2l +9zWbTHa2g7+L2zTlxTNmXfmMWL+WNscZ4kMImHGSax1j60RNU05y5ldaukAumN6muLZ 00wpsCflKYJi6tjnVxkVyecND3OQohGhVFkXZh93yGdWgkXZoxWnUf5a6TBIue0creZ9 mH8g1pVC9Ok8xc4k+trSQ+7doLNrnSbOLkWFzW2Fr1OtHUH3TMumRpeqwns+Nwlciykx EgUhKf148k6OhXksv0kXpQ2wSXXEX3xq+rpATo1L8cp3OpKdVgp0mMdWScebhywiGw/2 aqhw== 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:date:from; bh=zqNoB3N7qwxnLFRYuycRj11LRbS7fFAi+hgXw3H/zsA=; b=RakWMI5bCaeXbV7+jIWtIyS4ne0F4pR9HC7/OcZ2hOmMclp4P3w3O5WcUEV4Wr2zpr TfDnq0YHuqVjcshkw8vh36vj/32LLy8pR1LOyIzesHfj5eVZO9qU9vsAYtTl8F58iJ6F 7POTZNnJCzp+E+xjvuON+2YDe0VdUt6uLWplGFt45VTF/P4Ys4va4Eww7++ZhY8iq7b4 tKyYv0tj2s3NMbOKsNDQ+Dj7zPBlgoITIjP1dUydNED1tk2/8k/mEciciljTYiiUw+Ju LDJIbNw/ciBPTMzZbFmCfv2jFv8TLUGTZGUHPZg0AMFrNM06YAaScJTJsBnDAXJJFzqS 3reg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l190-20020a6391c7000000b00543ec6d7273si2619068pge.45.2023.06.07.00.22.52; Wed, 07 Jun 2023 00:23:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238723AbjFGHKw (ORCPT + 99 others); Wed, 7 Jun 2023 03:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238720AbjFGHKu (ORCPT ); Wed, 7 Jun 2023 03:10:50 -0400 Received: from fgw23-7.mail.saunalahti.fi (fgw23-7.mail.saunalahti.fi [62.142.5.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C210B19AA for ; Wed, 7 Jun 2023 00:10:47 -0700 (PDT) Received: from localhost (88-113-26-95.elisa-laajakaista.fi [88.113.26.95]) by fgw23.mail.saunalahti.fi (Halon) with ESMTP id 6b8f1cc4-0502-11ee-b972-005056bdfda7; Wed, 07 Jun 2023 10:10:45 +0300 (EEST) From: andy.shevchenko@gmail.com Date: Wed, 7 Jun 2023 10:10:44 +0300 To: Oleksii Moisieiev Cc: "sudeep.holla@arm.com" , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , "linux-arm-kernel@lists.infradead.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-gpio@vger.kernel.org" Subject: Re: [PATCH v3 2/4] firmware: arm_scmi: Add SCMI v3.2 pincontrol protocol basic support Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tue, Jun 06, 2023 at 04:22:27PM +0000, Oleksii Moisieiev kirjoitti: > scmi: Introduce pinctrl SCMI protocol driver Seems like you forgot to remove previous line(s) in the commit message and the above has to be the Subject here. > Add basic implementation of the SCMI v3.2 pincontrol protocol > excluding GPIO support. All pinctrl related callbacks and operations > are exposed in the include/linux/scmi_protocol.h drop include/ part, everybody will understand that. Also mind the grammar period. ... > -scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o > +scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o pinctrl.o Why not splitting it and make it ordered? ... Missing headers: bitfield.h bits.h byteorder/ types.h > +#include > +#include > +#include Missing asm/unaligned.h ... > +struct scmi_group_info { > + bool present; > + char name[SCMI_MAX_STR_SIZE]; > + unsigned int *group_pins; > + unsigned int nr_pins; > +}; So, why struct pingroup can't be embeded here? > +struct scmi_function_info { > + bool present; > + char name[SCMI_MAX_STR_SIZE]; > + unsigned int *groups; > + unsigned int nr_groups; > +}; So, why and struct pinfunction can't be embedded here (yes, you would need a duplication of groups as here they are integers)? As far as I understand these data structures are not part of any ABI (otherwise the wrong type(s) / padding might be in use) and hence don't see the impediments to use them, but would be nice to have a comment on top of each. ... > +struct scmi_pin_info { > + bool present; > + char name[SCMI_MAX_STR_SIZE]; Swapping order might help compiler to generate a better code. Also this applies to the _group_info and _function_info. > +}; ... > + ret = ph->xops->do_xfer(ph, t); > + if (!ret) { Can you rather follow the usual pattern, i.e. checking for the errors? if (ret) goto out_put_xfer; > + pi->nr_functions = GET_FUNCTIONS_NR(attr->attributes_high); > + pi->nr_groups = GET_GROUPS_NR(attr->attributes_low); > + pi->nr_pins = GET_PINS_NR(attr->attributes_low); > + } out_put_xfer: > + ph->xops->xfer_put(ph, t); > + return ret; ... > + ret = ph->xops->do_xfer(ph, t); > + if (!ret) { Ditto. > + if (n_elems) > + *n_elems = NUM_ELEMS(rx->attributes); > + > + strscpy(name, rx->name, SCMI_SHORT_NAME_MAX_SIZE); > + } > + > + ph->xops->xfer_put(ph, t); > + > + /* > + * If supported overwrite short name with the extended one; > + * on error just carry on and use already provided short name. > + */ > + if (!ret && EXT_NAME_FLAG(rx->attributes)) if (ret) return ret; > + ph->hops->extended_name_get(ph, PINCTRL_NAME_GET, selector, > + (u32 *)&type, name, > + SCMI_MAX_STR_SIZE); > + return ret; return 0; > +} ... > + ret = ph->xops->do_xfer(ph, t); > + if (!ret) if (ret) goto out_put_xfer; (but in this and similar, aka one line, cases the current wouldn't be bad, just matter of the consistency with the rest of the code) > + *config_value = get_unaligned_le32(t->rx.buf); > + > + ph->xops->xfer_put(ph, t); > + return ret; ... > + ret = ph->xops->xfer_get_init(ph, PINCTRL_RELEASE, > + sizeof(*tx), 0, &t); This is perfectly one line. Please also check entire code for such an unneeded wrap. ... > +static int scmi_pinctrl_get_group_info(const struct scmi_protocol_handle *ph, > + u32 selector, > + struct scmi_group_info *group) > +{ > + int ret; > + > + if (!group) > + return -EINVAL; > + > + ret = scmi_pinctrl_attributes(ph, GROUP_TYPE, selector, > + group->name, > + &group->nr_pins); > + if (ret) > + return ret; > + > + if (!group->nr_pins) { > + dev_err(ph->dev, "Group %d has 0 elements", selector); > + return -ENODATA; > + } > + > + group->group_pins = devm_kmalloc_array(ph->dev, group->nr_pins, > + sizeof(*group->group_pins), > + GFP_KERNEL); > + if (!group->group_pins) > + return -ENOMEM; > + > + ret = scmi_pinctrl_list_associations(ph, selector, GROUP_TYPE, > + group->nr_pins, group->group_pins); > + if (ret) { > + devm_kfree(ph->dev, group->group_pins); This is a red flag. Is this function is solely used at the ->probe() stage? I do not think so. Why then the devm_*() is being used to begin with? Also what are the object lifetimes for device here and the _group_info instances? > + return ret; > + } > + > + group->present = true; > + return 0; > +} ... > +static int scmi_pinctrl_get_function_info(const struct scmi_protocol_handle *ph, > + u32 selector, > + struct scmi_function_info *func) > +{ As per above. > +} ... > +static const struct scmi_pinctrl_proto_ops pinctrl_proto_ops = { > + .get_count = scmi_pinctrl_get_count, > + .get_name = scmi_pinctrl_get_name, > + .get_group_pins = scmi_pinctrl_get_group_pins, > + .get_function_groups = scmi_pinctrl_get_function_groups, > + .set_mux = scmi_pinctrl_set_mux, > + .get_config = scmi_pinctrl_get_config, > + .set_config = scmi_pinctrl_set_config, > + .request_pin = scmi_pinctrl_request_pin, > + .free_pin = scmi_pinctrl_free_pin It's not a terminator item, so leave trailing comma. It will reduce the burden in case of update of this. > +}; ... > +static int scmi_pinctrl_protocol_init(const struct scmi_protocol_handle *ph) > +{ > + pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); > + if (!pinfo) > + return -ENOMEM; All the same, why devm_*() is in use and what are the object lifetimes? > +} ... > + for (i = 0; i < pi->nr_groups; i++) > + if (pi->groups[i].present) { > + devm_kfree(ph->dev, pi->groups[i].group_pins); > + pi->groups[i].present = false; > + } > + > + for (i = 0; i < pi->nr_functions; i++) > + if (pi->functions[i].present) { > + devm_kfree(ph->dev, pi->functions[i].groups); > + pi->functions[i].present = false; > + } Missing outer {}, but see above as well. ... > +static const struct scmi_protocol scmi_pinctrl = { > + .id = SCMI_PROTOCOL_PINCTRL, > + .owner = THIS_MODULE, This is not needed if you use a trick from ~15 years back... > + .instance_init = &scmi_pinctrl_protocol_init, > + .instance_deinit = &scmi_pinctrl_protocol_deinit, > + .ops = &pinctrl_proto_ops, > +}; > + Redundant blank line. > +DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(pinctrl, scmi_pinctrl) ...i.e. initializing the owner by this macro. It might require some update to the above macro and its users. ... > +enum scmi_pinctrl_selector_type { > + PIN_TYPE = 0, > + GROUP_TYPE, > + FUNCTION_TYPE Leave trailing comma. > +}; -- With Best Regards, Andy Shevchenko