Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4366306pxy; Tue, 27 Apr 2021 03:25:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy218UKOBAU1fcBkSF5NmgE9E8AXjW5SA/VxCh4ySmJDv4HL3ieXUPS75tVdb1RA6oPD1aJ X-Received: by 2002:a05:6402:2211:: with SMTP id cq17mr3409760edb.28.1619519154861; Tue, 27 Apr 2021 03:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619519154; cv=none; d=google.com; s=arc-20160816; b=meyNOQoKNtpuvgjdSboSYkeyzcNxw6x3clhropMSreF4y9sRR+5gjWh9PDUW3exMxE INyHGmvzTsxgmBl6kZN15go/zxMrzBD9PsKd6LKWYSVJcT7fD4pl2+SnVKJ4Bw22fLYp zeZTYtEqJx89aE3iZdwo4uDKtyrxLXSMl4EmO+jPDKOYMhdVnD6nC5MDWbLcuCQb6UoF LG776RuP5iv1gfwfiHBQywOleJQnZnPRGJGEx+CedZ4beN9QGfTjz0X3a4EUTQCx6kYz K/sHvb5pxjkCPBQHYVob2a0ImTjhkSZkEsOabt0G8kQMAmvqBAu0gyXY6v+2M//7oQ+w CPbw== 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 :message-id:date:subject:cc:to:from; bh=WpmdMgamcdccyRmrQs287sjzdJKPyQElX3wmiFZdPZ0=; b=wZ3LWNHXGVtaLE7IfYOxThaLXqNo2cVvM3WEbQv/90GjpWTJLyo1iuwVqesu3B0dMC YCJZTQFdOmgZMDS/K0GaBP0GsEUBmHhYSlEkn/KOikr5TAlgtrJzVIf33/kShEIe2HSi S1fmH6P4Hs29Ck21N0qE+t7AE3XG1TFaAKq1WbemvlLy2MtCnyUxEbnH519bCIAEUBRN B4hzyzmLkt3r3eHi7rKEMppTMzFYg9qnoeBOINpuCbo2xnbiZCRbBSxZhrmkI2XrY7o5 XDfczwZt0VvvVRgr89f1fLU5Huj0b0doJ2P8T7ndoRWkusjb1k9spBob7uL2d+TZeMxi 0XGg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c95si2476098edf.106.2021.04.27.03.25.30; Tue, 27 Apr 2021 03:25:54 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235398AbhD0KZP (ORCPT + 99 others); Tue, 27 Apr 2021 06:25:15 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58499 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235351AbhD0KZN (ORCPT ); Tue, 27 Apr 2021 06:25:13 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lbKtH-0003oc-Dr; Tue, 27 Apr 2021 10:24:27 +0000 From: Colin King To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] gpio: sim: Fix dereference of free'd pointer config Date: Tue, 27 Apr 2021 11:24:27 +0100 Message-Id: <20210427102427.11066-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 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: Colin Ian King The error return of config->id dereferences the kfree'd object config. Fix this by using a temporary variable for the id to avoid this issue. Addresses-Coverity: ("Read from pointer aftyer free") Fixes: a49d14276ac4 ("gpio: sim: allocate IDA numbers earlier") Signed-off-by: Colin Ian King --- drivers/gpio/gpio-sim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index 2e2e6399e453..7bba5783a043 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -751,8 +751,10 @@ gpio_sim_config_make_item(struct config_group *group, const char *name) config->id = ida_alloc(&gpio_sim_ida, GFP_KERNEL); if (config->id < 0) { + int id = config->id; + kfree(config); - return ERR_PTR(config->id); + return ERR_PTR(id); } config_item_init_type_name(&config->item, name, -- 2.30.2