Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1079133iog; Fri, 24 Jun 2022 23:52:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ulEZC41sIKlVXzTbaN+ip99TsffNrzpZa/K1+q+IjDR+sBg9+GwYqK1uFzW+8L3KW1ttFO X-Received: by 2002:a05:6402:50ce:b0:435:9249:dfe9 with SMTP id h14-20020a05640250ce00b004359249dfe9mr3423242edb.310.1656139956799; Fri, 24 Jun 2022 23:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656139956; cv=none; d=google.com; s=arc-20160816; b=c5kybaFlufV7+O45wtlqq2WQi8Z7OhL/AaguMEEYTWprdjEMO1ibgxmHPfVME/u3M3 5xWREbhFUAqazWETgTy32ElGrHAvymEPuNXCePRFZ0iss1Niyg0j9CUNSwLGhFzTZI1Q SqjYso92ONhzXccjD6bzCBo+sNRPpMtr9ql28IF7lfAjMQmSg/3NTdgqvVCc8K+tpVkh sz4IVz5DUuvg0EDPTLa9d8WiGfBrcSKv/ShYe36HTE4atjmyHrWq/85AMtdLzOBM6saU bkwk2iiYmvbhS4Rx0wv78oEiJhPsYfgEAYV1Cw9nCuG7AzpfHwVjFhlfDmAr+T5uaGe+ C0dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=lcB8q/3cT5M80u9jyNf5j1FIPYUSA5nUzf7XJ9n26Yc=; b=LnjHrJMfSos+DlLUghcLQD2K5X1U2PpTpLUAYbxtLEfolH5hSLqCIKRZ+FjJNDGM7k FHn9naTaKQbAg6jSPAMUnR2dz4P1RSt8lhQRgJlY6T7GMRXOk4NlGS1RBJAiOUniFsUM Jz+aL3T4HZ/HFuR8g+CweWDT8nTSj7outN5AG4uZMluuntb21t+5NqU799siEYxERGm8 mPVyR652GzgvKcUQ74LkGswOPs7bXwzwtOFXl4FZXNh9uQKpbjfwrNYX1DRpxLNvpcCK q/IlSvySi8iGKpR/r2oI4lh+UUKxpgxaxQzzNx5YjlJ1Fq9Ys1+d0LUyL3erlCMfkBMJ DwtA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a1709064fcc00b00726379f7466si3785397ejw.674.2022.06.24.23.52.00; Fri, 24 Jun 2022 23:52:36 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232080AbiFYGh7 (ORCPT + 99 others); Sat, 25 Jun 2022 02:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbiFYGh6 (ORCPT ); Sat, 25 Jun 2022 02:37:58 -0400 Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38BA6CCE for ; Fri, 24 Jun 2022 23:37:56 -0700 (PDT) Received: from [192.168.1.18] ([90.11.190.129]) by smtp.orange.fr with ESMTPA id 4zQToScCo6rrE4zQTo0f6d; Sat, 25 Jun 2022 08:37:53 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sat, 25 Jun 2022 08:37:53 +0200 X-ME-IP: 90.11.190.129 Message-ID: Date: Sat, 25 Jun 2022 08:37:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 2/4] usb: typec: ucsi: stm32g0: add support for stm32g0 i2c controller Content-Language: en-US To: fabrice.gasnier@foss.st.com Cc: alexandre.torgue@foss.st.com, amelie.delaunay@foss.st.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-usb@vger.kernel.org, robh+dt@kernel.org References: <20220624155413.399190-1-fabrice.gasnier@foss.st.com> <20220624155413.399190-3-fabrice.gasnier@foss.st.com> From: Christophe JAILLET In-Reply-To: <20220624155413.399190-3-fabrice.gasnier@foss.st.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Le 24/06/2022 à 17:54, Fabrice Gasnier a écrit : > STM32G0 provides an integrated USB Type-C and power delivery interface. > It can be programmed with a firmware to handle UCSI protocol over I2C > interface. A GPIO is used as an interrupt line. > > Signed-off-by: Fabrice Gasnier > --- > drivers/usb/typec/ucsi/Kconfig | 10 ++ > drivers/usb/typec/ucsi/Makefile | 1 + > drivers/usb/typec/ucsi/ucsi_stm32g0.c | 218 ++++++++++++++++++++++++++ > 3 files changed, 229 insertions(+) > create mode 100644 drivers/usb/typec/ucsi/ucsi_stm32g0.c > [...] > +static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, const void *val, > + size_t len) > +{ > + struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); > + struct i2c_client *client = g0->client; > + struct i2c_msg msg[] = { > + { > + .addr = client->addr, > + .flags = 0, > + } > + }; > + unsigned char *buf; > + int ret; > + > + buf = kzalloc(len + 1, GFP_KERNEL); Hi, Nit: kmalloc() would be enough here, the whole buffer is written just a few lines after. > + if (!buf) > + return -ENOMEM; > + > + buf[0] = offset; > + memcpy(&buf[1], val, len); > + msg[0].len = len + 1; > + msg[0].buf = buf; > + > + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); > + kfree(buf); > + if (ret != ARRAY_SIZE(msg)) { > + dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, buf[0], ret); Use-after-free of buf. > + > + return ret < 0 ? ret : -EIO; > + } > + > + return 0; > +} > + Just my 2c, CJ [...]