Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2857822pxb; Mon, 18 Apr 2022 09:41:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5PoHyCFuu80jyxAXV0jUmpsc0wefsk+NvZy2GndySCAoOLXibdOf1edg1yQ1EkKavVDQj X-Received: by 2002:a05:6402:5215:b0:423:8bd8:f8ce with SMTP id s21-20020a056402521500b004238bd8f8cemr12267877edd.250.1650300089407; Mon, 18 Apr 2022 09:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650300089; cv=none; d=google.com; s=arc-20160816; b=evh7qs7rNe6AGMJcrNkoCvTou4dN9aAUfzlP6wZ3tmwuBQ1ve4MUxBLbwbz+RYRIpv DeX6ccaCO++XMAikflLZZMHs+YPmrE3qxhz/AHEJS4UCCsQPzgrLRMew9yfso/zWHbl8 kMgY2NzEn+a8TKdOC4z9lEYhV9Sc27gRKg89k8OFYR1139lgtSQDu+AiCEs5WZRYzX4A ZH9mKTO1NpOyhX/sdUklVD9SVJKO2lFduzG8k3V3N6I5tBVdc2w+zMMzKud4ixUzm5fc gfXhdS9ELj9Oy0Cx5dsDtyi8HnDgJ/5Ag9eYY79LUXAbmJqzvjzVXi9eeKSrvY6jhHuJ 3kGQ== 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=kLHJ3N8q6OFleGyy+MHKaOmg+HMQvFhkHwF5ae1gShk=; b=HieikE6wTklfKc+mOfCziMTceRWmv2uTI5e2RXFXyTPb4h8yrFNV4V/pY/eYi5MOqG djjr3c6uxxo7HpxQrsTYkTIOc7uDFlOJU/DKiQ/8KXlV+iZuudvRP5fZ1btCVfdtSz6P fcfmsE4SeeNV4WHxwyo6MoAraF5ifBOTLg1hYSHjGUXvUvmajfi1LXhs1JdOHVGsLW9h qJiHuEF8XKzZ3EfgSSsyd+LADZoW0A7L3cHsYXWJWHXFfIZOfdaP7ESdZJ+W4vKd2LRO JBRKGYXmolcq3uph8z8MZg4gH7JLGMCYVKsMscMhZUqd4Kwj9oCDPeBtTeqD7jPborm5 8Nsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h4Sx3TV0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020a05640234cd00b0041d38202363si7640566edc.500.2022.04.18.09.41.04; Mon, 18 Apr 2022 09:41:29 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h4Sx3TV0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240262AbiDRMiu (ORCPT + 99 others); Mon, 18 Apr 2022 08:38:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239756AbiDRMdX (ORCPT ); Mon, 18 Apr 2022 08:33:23 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB9B91E3EF; Mon, 18 Apr 2022 05:25:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 22184CE1099; Mon, 18 Apr 2022 12:25:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8465C385A1; Mon, 18 Apr 2022 12:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284729; bh=in+Tjq7u2HtEgipwNeDYze3KLACNyZ5YX46Zm/zoWb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h4Sx3TV0D62WbFN67BEILoo9hpc9NAAEORmbb43kAHJMjfjpcxcGQjg92ObLcDYm/ f5mbcHlHiLMlLebn17KBqZCG7CC9b5yyM5BhadhBdGUjeAzvS7gB0UQOk2cxJBAGMf GCrdEPD1PjO4aT8gB8Lklw12A82cADEdhu/zKPbs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Wolfram Sang Subject: [PATCH 5.17 208/219] i2c: dev: check return value when calling dev_set_name() Date: Mon, 18 Apr 2022 14:12:57 +0200 Message-Id: <20220418121212.690559498@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Andy Shevchenko commit 993eb48fa199b5f476df8204e652eff63dd19361 upstream. If dev_set_name() fails, the dev_name() is null, check the return value of dev_set_name() to avoid the null-ptr-deref. Fixes: 1413ef638aba ("i2c: dev: Fix the race between the release of i2c_dev and cdev") Signed-off-by: Andy Shevchenko Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-dev.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -668,16 +668,21 @@ static int i2cdev_attach_adapter(struct i2c_dev->dev.class = i2c_dev_class; i2c_dev->dev.parent = &adap->dev; i2c_dev->dev.release = i2cdev_dev_release; - dev_set_name(&i2c_dev->dev, "i2c-%d", adap->nr); + + res = dev_set_name(&i2c_dev->dev, "i2c-%d", adap->nr); + if (res) + goto err_put_i2c_dev; res = cdev_device_add(&i2c_dev->cdev, &i2c_dev->dev); - if (res) { - put_i2c_dev(i2c_dev, false); - return res; - } + if (res) + goto err_put_i2c_dev; pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); return 0; + +err_put_i2c_dev: + put_i2c_dev(i2c_dev, false); + return res; } static int i2cdev_detach_adapter(struct device *dev, void *dummy)