Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp509467lqp; Thu, 21 Mar 2024 07:47:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUQfzxBTDTfsArk8495aEeflxOV2eYjj9FoGX+Mst/pWnPnoKK9Fe9Wi/OV+WF3f9HeS4EzNJDvCrs6hFnSojh4hEgE6ur6crpliA63eQ== X-Google-Smtp-Source: AGHT+IH8PswWn0H2AHitXvODRI94H2D0prbGAAnsd8YfyohKFf5DQspQRQfuK0tWPG6MZIogSBBa X-Received: by 2002:a05:6a20:9589:b0:1a3:6f98:f677 with SMTP id iu9-20020a056a20958900b001a36f98f677mr11498641pzb.8.1711032431507; Thu, 21 Mar 2024 07:47:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711032431; cv=pass; d=google.com; s=arc-20160816; b=L/+osIoCJBxmHkpWDQqZYupasLMXzxB1grAlnULQOHfVs0zzleU+Pkcet4dd/2CbEj F4Ca2eci3pjWMZR4roP+I6kdBRCREfy53mqQT+kOyjzk8KLthLB0bRFvlP6ubHKBJw4s 1qf+4L0bvU4bt8qLCg2KKxTP/uCyUV4yOdTWau/McTgWj4NDmvg95TYizscINRde4nDp YzMlc0w5PKxKelZBgjp0ns7qsA8YxYVui9YzCSFs/pGvw2qio4WrZRTksZW0l6/IEwhJ IOUA9c4EZM9x5dd7x/c7HeUkT14dEqon9/IRC+54TphAUVBCEM1ed/aPBkWC88AWZOkp cvpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GdJRKQkpHq/YxzYas4fiwyUxsBkDgVSnKvrwtVatzEg=; fh=vbCKt/1Fg3ag3yNpOwdGmqMSt9l0m7RMkagFy455EzY=; b=1KDjaVeCwytf34jsHxU/0hohGBzq32xcfedmru5Jw+OOpf5qRUoO/mgHvZDkuUHZ+f H23cfTDkj2ftLHeHu/q6mAghFyM505GZzF6TeVkimtpNYfaifPHMwizcGef/pbd/yYa5 znMJhNWPoJpOtC5gMtB6MrOQELv9roJl33KJDxjhoVQO+Uu+dgyVysTUaEkVyazyKCyk BJ00BvCnI/WcQ+PiT5r21n5UhQUoZ9dCFNubfhNoPkClwJhpVdMM8bfHDb2qHaMHsFaR HqN/bqmJFMNiq60yM5hcqNsFiOyOmWDg7ERBSYN12GzUNOaMfHyL55XkFlJIoCXD9bN5 1BcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VSBDnCTF; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-110176-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f21-20020aa78b15000000b006e7137c1b04si10335228pfd.282.2024.03.21.07.47.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:47:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110176-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VSBDnCTF; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-110176-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2B4BB28481B for ; Thu, 21 Mar 2024 14:47:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA55585945; Thu, 21 Mar 2024 14:47:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="VSBDnCTF" Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A24E2CCA3 for ; Thu, 21 Mar 2024 14:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032421; cv=none; b=rtA8BQKTYsopFd2BuWPAQJp/A1GKrVZe12BqjTgkASueTmPlx2TW7f3oTAdutgLykCoG/i/Rhh7th6HiBmh/VVZ/Sno3ZVKAZ81CXnxS6ixNfTbPfw4AImBXN629A7NlFVx6Cs30vlSbQA7MONDZ+jIk97+KpOmocH2FN85tkbQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032421; c=relaxed/simple; bh=llYZX8Vl06P5c584RK2OPZBrLHRSgxPJegX38T4GB3s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tgFDjAEt4RK1+oQmk8heiSYsVOxZ4rkjqOxwOMOq0bFFepFhlQX0cAJ7Gz1xfFCneP1zZzxYNRZZIbkhFaP8o5zpSJvNM1PlcCi75tvmEVHPxnD8mLOYJUK63l9Vn8S3Ux05oFV4lg8HcKXGEJTf1njiEbSmvt8Ntz+MvgLGdcA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=VSBDnCTF; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-33ec8f13c62so734963f8f.0 for ; Thu, 21 Mar 2024 07:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711032418; x=1711637218; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=GdJRKQkpHq/YxzYas4fiwyUxsBkDgVSnKvrwtVatzEg=; b=VSBDnCTF/AkcJVBQiNxmNKQn6lKMYm90FR5hRSt8ak+FHbO5fDNetY1sjFbnJy2ge4 7jDnoawPwfZ4ZzytLu9PKou2GLxvvgoVJcYL6lTuVvreryl5D6KMuRp9pOsMUowcn1Ad gUszo1dgUIJuNtF4RSNJLU5CZMUfFc2xikuIx0FOIn+wdFe9yIoeQiDczvYOY/2mBz83 BOiNWSp+sVkBRmf+W+uLV1ieFxgTjIZuXpkrrTr3BKCUAiptqX0WUw0XBKgdxFKhb9k+ YgTWiy1C7VYpBb/fkDh7wad0Fjdlf8DfS5L0uWk/d9qqJIdm/qq5k+4VKEmKBA3RtqZl jl9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032418; x=1711637218; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GdJRKQkpHq/YxzYas4fiwyUxsBkDgVSnKvrwtVatzEg=; b=qNVlISTqUkV+hoDetj25PBOLA7Tg3vJyxB0Msw2ug5cimZyxkKaIlmDl5nVQ0ltCiI AZV1AX/KT5dlFnJrIVz88K781MCwqG1ff5scMtyUnsSCwNjUXXuZMghO/zuSENxSPx/o nm9T6465JZ8CMvLLLmMr7dhT/DW5XP4h5mk8thNPMCDhmNWNT5bTUyfGG8lNb2/eb3Iw Lk/Ilsu00skvccTLbxyo+gao2qQGM8WxKkGsbhKNcJXlx1Ga4GmUXAQuLo+Q6AIOJJXf Hm1cOJuNMWmuSCNi5j15+B5/NLaP8NbC7XEICx49mgv/aXqy+genuMht2dw3NZyfhf5b qZHQ== X-Forwarded-Encrypted: i=1; AJvYcCVbVdbDH84d5Jsb09c4S6aZxUaVB9RPdZiFoQnw4/5mfGRxXPEumUEjRZxw/+jzGYFcQt78p74tPQIVNxiK24Jf98BFPdvbsGoaqN6w X-Gm-Message-State: AOJu0YyGthcIGKHs9olLtm54M91gmeo8vNeRo9TK61a47m0UjMKJsqXm X3MHaim+0eCQ6FVmyLrMZP08AD1pJZtOQsHK73X21SvUD6Sysap7mew7qUYsOQQ= X-Received: by 2002:a5d:4d43:0:b0:33d:7e99:babc with SMTP id a3-20020a5d4d43000000b0033d7e99babcmr1645482wru.50.1711032418202; Thu, 21 Mar 2024 07:46:58 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id ba29-20020a0560001c1d00b0033ec8b3b3e4sm14638421wrb.79.2024.03.21.07.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:46:57 -0700 (PDT) Date: Thu, 21 Mar 2024 17:46:53 +0300 From: Dan Carpenter To: "Peng Fan (OSS)" Cc: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, AKASHI Takahiro , Peng Fan Subject: Re: [PATCH v5 3/4] firmware: arm_scmi: Add SCMI v3.2 pincontrol protocol basic support Message-ID: <7a4a8287-1f86-4ac4-acdf-c02339ba5e1e@moroto.mountain> References: <20240314-pinctrl-scmi-v5-0-b19576e557f2@nxp.com> <20240314-pinctrl-scmi-v5-3-b19576e557f2@nxp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240314-pinctrl-scmi-v5-3-b19576e557f2@nxp.com> On Thu, Mar 14, 2024 at 09:35:20PM +0800, Peng Fan (OSS) wrote: > +enum scmi_pinctrl_protocol_cmd { > + PINCTRL_ATTRIBUTES = 0x3, > + PINCTRL_LIST_ASSOCIATIONS = 0x4, > + PINCTRL_CONFIG_GET = 0x5, > + PINCTRL_CONFIG_SET = 0x6, > + PINCTRL_FUNCTION_SELECT = 0x7, PINCTRL_FUNCTION_SELECT was removed from the spec so the other cmds were renumbered. I'm still going through and reviewing this file. I'll hopefully be done tomorrow. > + PINCTRL_REQUEST = 0x8, > + PINCTRL_RELEASE = 0x9, > + PINCTRL_NAME_GET = 0xa, > + PINCTRL_SET_PERMISSIONS = 0xb > +}; > + [ snip ] > +static int scmi_pinctrl_attributes(const struct scmi_protocol_handle *ph, > + enum scmi_pinctrl_selector_type type, > + u32 selector, char *name, > + unsigned int *n_elems) > +{ > + int ret; > + struct scmi_xfer *t; > + struct scmi_msg_pinctrl_attributes *tx; > + struct scmi_resp_pinctrl_attributes *rx; > + > + if (!name) > + return -EINVAL; > + > + ret = scmi_pinctrl_validate_id(ph, selector, type); > + if (ret) > + return ret; > + > + ret = ph->xops->xfer_get_init(ph, PINCTRL_ATTRIBUTES, sizeof(*tx), > + sizeof(*rx), &t); > + if (ret) > + return ret; > + > + tx = t->tx.buf; > + rx = t->rx.buf; > + tx->identifier = cpu_to_le32(selector); > + tx->flags = cpu_to_le32(type); > + > + ret = ph->xops->do_xfer(ph, t); > + if (!ret) { > + 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)) ^^^^ Dereferencing "rx" after the ph->xops->xfer_put() is a use after free (racy). > + ph->hops->extended_name_get(ph, PINCTRL_NAME_GET, selector, > + (u32 *)&type, name, > + SCMI_MAX_STR_SIZE); > + return ret; > +} [ snip ] > +static int scmi_pinctrl_request(const struct scmi_protocol_handle *ph, > + u32 identifier, > + enum scmi_pinctrl_selector_type type) > +{ > + int ret; > + struct scmi_xfer *t; > + struct scmi_msg_request *tx; > + > + if (type == FUNCTION_TYPE) > + return -EINVAL; > + > + ret = scmi_pinctrl_validate_id(ph, identifier, type); > + if (ret) > + return ret; > + > + ret = ph->xops->xfer_get_init(ph, PINCTRL_REQUEST, sizeof(*tx), 0, &t); Missing error check. if (ret) return ret; > + > + tx = t->tx.buf; > + tx->identifier = cpu_to_le32(identifier); > + tx->flags = cpu_to_le32(type); > + > + ret = ph->xops->do_xfer(ph, t); > + ph->xops->xfer_put(ph, t); > + > + return ret; > +} > + > +static int scmi_pinctrl_pin_request(const struct scmi_protocol_handle *ph, > + u32 pin) > +{ > + return scmi_pinctrl_request(ph, pin, PIN_TYPE); > +} > + > +static int scmi_pinctrl_free(const struct scmi_protocol_handle *ph, > + u32 identifier, > + enum scmi_pinctrl_selector_type type) > +{ > + int ret; > + struct scmi_xfer *t; > + struct scmi_msg_request *tx; > + > + if (type == FUNCTION_TYPE) > + return -EINVAL; > + > + ret = scmi_pinctrl_validate_id(ph, identifier, type); > + if (ret) > + return ret; > + > + ret = ph->xops->xfer_get_init(ph, PINCTRL_RELEASE, sizeof(*tx), 0, &t); if (ret) return ret; > + > + tx = t->tx.buf; > + tx->identifier = cpu_to_le32(identifier); > + tx->flags = cpu_to_le32(type); > + > + ret = ph->xops->do_xfer(ph, t); > + ph->xops->xfer_put(ph, t); > + > + return ret; > +} [ snip ] > +enum scmi_pinctrl_conf_type { > + SCMI_PIN_NONE = 0x0, This is SCMI_PIN_DEFAULT now. > + SCMI_PIN_BIAS_BUS_HOLD = 0x1, > + SCMI_PIN_BIAS_DISABLE = 0x2, > + SCMI_PIN_BIAS_HIGH_IMPEDANCE = 0x3, > + SCMI_PIN_BIAS_PULL_UP = 0x4, > + SCMI_PIN_BIAS_PULL_DEFAULT = 0x5, > + SCMI_PIN_BIAS_PULL_DOWN = 0x6, > + SCMI_PIN_DRIVE_OPEN_DRAIN = 0x7, > + SCMI_PIN_DRIVE_OPEN_SOURCE = 0x8, > + SCMI_PIN_DRIVE_PUSH_PULL = 0x9, > + SCMI_PIN_DRIVE_STRENGTH = 0xA, > + SCMI_PIN_INPUT_DEBOUNCE = 0xB, > + SCMI_PIN_INPUT_MODE = 0xC, > + SCMI_PIN_PULL_MODE = 0xD, > + SCMI_PIN_INPUT_VALUE = 0xE, > + SCMI_PIN_INPUT_SCHMITT = 0xF, > + SCMI_PIN_LOW_POWER_MODE = 0x10, > + SCMI_PIN_OUTPUT_MODE = 0x11, > + SCMI_PIN_OUTPUT_VALUE = 0x12, > + SCMI_PIN_POWER_SOURCE = 0x13, > + SCMI_PIN_SLEW_RATE = 0x20, ^^^^ This is a decimal vs hex bug. It should 0x14. I think this enum would be more readable in decimal anyway. > + SCMI_PIN_OEM_START = 0xC0, > + SCMI_PIN_OEM_END = 0xFF, > +}; But I'm still trying to review the code so I'll probably respond more tomorrow. regards, dan carpenter