From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8003C54E58 for ; Thu, 21 Mar 2024 14:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ydWAbG6v+5LiZ/QT94/YUtfL48+06xOq/+PBthj55Jg=; b=MvvCuOEAMdI7ta FJ5uR6WSaQCuUq0g1k3RVhENOh6/eOdXMsN5dslTOMoz86NMrPApCNRRznUr54W8gM8pROlB/WrRc iTd07m73i/oPDbVQLJRIo9wYBV5Ll2o1yGY4h2gMSGKfIIWVbFH8KR/MVPrPGbaCD1xQbegJqaHFT 51qekyChNS2MQxjsNHw4rYN4Ac6oiy5f7Fa1q4lWhOfsJHyu45t98bV7WPkVeJwH5A7vgr611bm37 Cri+jkrYS5Xup3fwerZgUOwDccsc1MVNA5X2g4mY3R5JzFKdK6+DIWhAtvaeVtuAv5Nn21gZWSYhJ i9Vpuwgpx+JmuXKAfLZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnJhA-00000003L7C-2C62; Thu, 21 Mar 2024 14:47:04 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnJh8-00000003L6K-0Uas for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2024 14:47:03 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33ec8f13c62so734961f8f.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=lists.infradead.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=aCiBIju2LsaVmToEGyH3ImHeLy1VKS5JUD7S4XXctqkvlQhwxHTNhvJ4/sBGooqCnp vnp99wfFVLNcvrnngG+W59eT2lBHFezc/+l6Hla792nbIaY4TgPMusYPr423wiPwsDh+ 6phpIefJ8WmbQpFwv36ELMnhDoxmObWNp4q5YSrghTfYAPKAgoIDxcy8OJlCeqvmAiq3 ZXnyzMK/5ZUlPjo1xlFcq5bTeK//3pz47sMxj1Vp7HzhCofvsvuxeTypVDk1zveviASc 2hzJQHgFZtVv3otB4rxDS2IQt/pPvzVtgLoi0lKEqQ1NQ2x9UtN4Zfc6cIqvI1A62ej/ Qs8w== 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=lUsmekYqlmh9Q3/HO6UwripVNn/Y42u1MbLUgNtWC3ms0B0keO6qVMhiLn/WNrZiIx MEQrAVGRXQTSqVlNtrlVguMWCDn5CavfmqJuzcSTa/rmrhePBUV3BmEtcsTqJPwNqMjd EV1URd4NyC4/gA7LOuYTj23M9HUBxI14nZtVirPeLHE441fXEE6NHM1XjV8dhxazEiaL 4K2fr66+zCJcMey8svtw9aEpIhJiP6uXRuGwQB96OpKQ88p2b6wkqC/K3aeXxPSahcPx LmfJiQfPgmAa5XUY2BiJxnPAcw8B4wQdA1MMCbmhQnKvtWiXoPosMJGgsZVhqWG1skny FCMw== X-Forwarded-Encrypted: i=1; AJvYcCWUYKvGvrtf59391OngTvO00/MS2dRXpzvpxcQ12yRC3Wm33IK9OVHqrz8uM9xm4+0mVdxwcMvDQi0HY77XtgtylFcHNhgdKXO6mIMQvJG86/00y1M= X-Gm-Message-State: AOJu0YzBVe6uLn/3477eoqNOvakN6PVfiuuFUDrsOlA4zuptTHuObBax nRvwZV2Nyw4cHBULJVeU503XWIZumCf7OY3L9ZhoTaKePh8CcFmXGS0FcZG4Wso= X-Google-Smtp-Source: AGHT+IH04y0b0igFcDFoi4qlbIk3SgKxtpe4cx0nnRjzZKbl25rVbNghBibtyOWy/RsfJoVtiUlNEA== 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240314-pinctrl-scmi-v5-3-b19576e557f2@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_074702_194680_07EF114A X-CRM114-Status: GOOD ( 16.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel