Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9039663pxu; Mon, 28 Dec 2020 05:09:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsFk+u+AyyhgKQoRkT+CYdE7OexxcJp87iGnILs/FkYIzsIReRB5mWCjK7mglVpO2djbgq X-Received: by 2002:a05:6402:c0b:: with SMTP id co11mr41402348edb.180.1609160963524; Mon, 28 Dec 2020 05:09:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609160963; cv=none; d=google.com; s=arc-20160816; b=FFuZ4c+i4qddgyQkaIMjJkf4TWDhc+tNXApT4qnVEkjjerxDNMxaVCl8GJ12meroQW Yu7DjG/jz+oevWl5ywqjADrGzvWaA2YYvvgBmu62Nd7be2zOjYrjeCiB62XSnD8dSmOW RNPgkcs/Oz0DoL9ikjVP951W455DGijhnHCF9iDcGb56Rt1N41CUoXhoIZk3zVDpS1rG UJNxEogb5XeMqWgazgShJzB+np6kA4/EchMYPvp9oA3S8ZQfGHkU+KoYZuU2i/Ip36OS 1tZjN+iGg7qIm6HldyhvQ6Q5AmYrNR2jSCfayvNnSTzsj3Hh5qAthSJWuxCKn9IGtnuJ 6upg== 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=rxp+WQ97RB+Wq/h0VItxe/gBLLqvwUd11fZmVuWzZ18=; b=dLLsrFkL/c0LoHSvuTUu0nFXk+qKjAxfQmUmjpg6BVB0mdZK/8Nb66+MUQ2N3Ct55E GPKWlPVeyOjbNMhiZVgIiq5YNztyV4VjDWM8Ixm+cD8xGRBCFpPSP64drsir7wOyW+xY PDrTbvEHpY1/QywpcLhHc6pAMqD8QgA4NTODmt8sVPXjHNmEGz5/IAiLHD9MLU67Y/yr NW99S5Va3d0Ou8Y6sDzw4OQP7cxBo3bwZXmPYjInP1gbXaiLGRIBEOXzmBHXIELRzrSe MzCk+ewcu0w0AgQE0gt2DPjc7Z7kl8225aQaSAK7lFkWPQQFKC3fi0C2PnYsFP8Gc3fE 4Lsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qog3up1z; 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 z4si18384715ejw.380.2020.12.28.05.09.00; Mon, 28 Dec 2020 05:09:23 -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=Qog3up1z; 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 S1728807AbgL1NHH (ORCPT + 99 others); Mon, 28 Dec 2020 08:07:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:34616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729858AbgL1NGw (ORCPT ); Mon, 28 Dec 2020 08:06:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A0D9208B6; Mon, 28 Dec 2020 13:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160771; bh=X9HNZ+ASp+IG55Xm89EYEWHTOUeAR9+dTbE1hmThyWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qog3up1zmAvROPJXUU4xt7KNZOefNY08www6J6o/Gm0hfoZ1GUPApu9dzpEencsAd 0ADkA2X8qq/IzvgEn7a0NvtnWBVUaMwJWTdvFf628Unl6ql3sdp5RR1uBnT7mO78a9 PrUwCxkQbVuDrjgMBMXEsSLUFzNo8jY7NiKEmIWU= 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.9 166/175] spi: sc18is602: Dont leak SPI master in probe error path Date: Mon, 28 Dec 2020 13:50:19 +0100 Message-Id: <20201228124901.278663533@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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 @@ -247,13 +247,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; @@ -304,15 +303,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[] = {