Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9168978pxu; Mon, 28 Dec 2020 08:17:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyq6fWQOczN80tcM43elA5ELl+luL5ZVaDFLaFEOH4ilsbrF58M/245AjsIyeQL3rZY7MJ8 X-Received: by 2002:a17:906:3883:: with SMTP id q3mr42050976ejd.160.1609172237003; Mon, 28 Dec 2020 08:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172236; cv=none; d=google.com; s=arc-20160816; b=uJl1wppK8gbIwiikzii6NR2Q0IPzUxYrcDmsjNuGZVtCizgl2KfMNJTVvRYdN83TG3 7o4o5prBVA8Q7Mouhfe/N4+xq4LfCtJMhJfHmjXyBb/zqFkcUEZ/jEZ1jTDB/mBmE4yM m67/7HpfqXDELXpx0GN77aD/huKdVYmRvnEh/cGttBx1mLWSGy+5f/mJoZ5lDOtTvyvu N3D5eRheweirFeXzXSMJpnu4pvROy889SIKdiG+cMyZ4inPPJBHmsQX7ywO/Sn/1elug C4Elr3wKNJlf2W+p4VQ85Cx/UvBRvtlyLk2hOMc0Mkt4MXnSyxZAQbc1LX3b6mFgZBvy C5GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hPXvEQpRf4zdjZ6EwOvrOj43Hu5Kgt86bVhjmHBfTx0=; b=lmiFEA6RLl+EEV4miVG4GPCE5QepsPFk5STGwhKSPIbjYSFa/x1l4kKUfcGYdx1MAl sjD4CzIOTlwe/9wEMnRTPUHdSaR6lIxolfTaArt3Td/4YYFlIbiS8UsO0lO9RfryekVj fazMTlw2Ti6KYLuhqhOEz+kLXXhYvHKmf6XQ07HenHwdOCAVT7jzlGiGBf6ioVlwnYEL 0i51M/gVua78nnfba/vTSTrDz0vS/y03X4DABxqMEwY28g9EVp1qHlyrFA4qnPeP89mE qozKigM95fB9f6TdYNXQ50kFFps7KtVrAXHAPJhkWzcz1DowjFAY0BCUzpJ4FGKuwLD5 7KXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M86UWaP0; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si18262069ejo.619.2020.12.28.08.16.54; Mon, 28 Dec 2020 08:17:16 -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=@linuxfoundation.org header.s=korg header.b=M86UWaP0; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731779AbgL1NSh (ORCPT + 99 others); Mon, 28 Dec 2020 08:18:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:47104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387521AbgL1NSd (ORCPT ); Mon, 28 Dec 2020 08:18:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C23321D94; Mon, 28 Dec 2020 13:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161472; bh=myJXd/ejH3AtWz8r5FJjFiaPuC1NOfsQw5brZ6bn/5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M86UWaP0ALu43hISx2hjqSGQc3n7D4l0ynjdjZkmqGrhZnAxOW8Mja6TLi88Qkuaa ByQ2d+9AnrOQ4P0Uj4YBzkDSKRRZnXo9CJEYXcN2Ok67+zJFPVxRLebTwhdb4CJBxi yJY0j+yh13vlmbNMVifE3YGNbCpS7A0AxgfjU734= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Phil Reid , Mark Brown Subject: [PATCH 4.14 224/242] spi: sc18is602: Dont leak SPI master in probe error path Date: Mon, 28 Dec 2020 13:50:29 +0100 Message-Id: <20201228124915.700979989@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner commit 5b8c88462d83331dacb48aeaec8388117fef82e0 upstream. If the call to devm_gpiod_get_optional() fails on probe of the NXP SC18IS602/603 SPI driver, the spi_master struct is erroneously not freed. Fix by switching over to the new devm_spi_alloc_master() helper. Fixes: f99008013e19 ("spi: sc18is602: Add reset control via gpio pin.") Signed-off-by: Lukas Wunner Cc: # v4.9+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v4.9+ Cc: Phil Reid Link: https://lore.kernel.org/r/d5f715527b894b91d530fe11a86f51b3184a4e1a.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-sc18is602.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) --- a/drivers/spi/spi-sc18is602.c +++ b/drivers/spi/spi-sc18is602.c @@ -248,13 +248,12 @@ static int sc18is602_probe(struct i2c_cl struct sc18is602_platform_data *pdata = dev_get_platdata(dev); struct sc18is602 *hw; struct spi_master *master; - int error; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) return -EINVAL; - master = spi_alloc_master(dev, sizeof(struct sc18is602)); + master = devm_spi_alloc_master(dev, sizeof(struct sc18is602)); if (!master) return -ENOMEM; @@ -308,15 +307,7 @@ static int sc18is602_probe(struct i2c_cl master->min_speed_hz = hw->freq / 128; master->max_speed_hz = hw->freq / 4; - error = devm_spi_register_master(dev, master); - if (error) - goto error_reg; - - return 0; - -error_reg: - spi_master_put(master); - return error; + return devm_spi_register_master(dev, master); } static const struct i2c_device_id sc18is602_id[] = {