From patchwork Fri Sep 15 12:34:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 723766 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FE04EE645A for ; Fri, 15 Sep 2023 12:34:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234909AbjIOMef (ORCPT ); Fri, 15 Sep 2023 08:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234836AbjIOMef (ORCPT ); Fri, 15 Sep 2023 08:34:35 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18175115 for ; Fri, 15 Sep 2023 05:34:29 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-401187f8071so14212665e9.0 for ; Fri, 15 Sep 2023 05:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694781267; x=1695386067; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RVVMN1mfiscodsKEBeruRJeoQBVr3gDmNiAY/CIpgV4=; b=IjCgxh87TBiHrV1SE6ETHbMXrIYYWElNSmmjo+YusbsU5KiOADizOqGsODOtKaYmNZ DKr82XMgGZkCciJRgR4FfjDYXhCBlT5uDfI1sIwlhTJSuZAC6rK+ZYyLVvAZ9kkUBaKs mjsCFPNp2PkOOlIitWPlMDUmhS3N58eeJaGl8s0b488Jh3BUFSeTgVGgf/CMSwPmd/D2 IeSsSmnw93A03Hnuui3SLdLBxM37wgYEe8cYP3Icz2IFSiHgv8K8G+L+7TicvCpV64/F Ewgo2JdwdxhwTdunnsO2Ixw0PQItgTLmChqEAivKazzyefDBNw/QGdX8VsoZe9oJgQwS 3FsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694781267; x=1695386067; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RVVMN1mfiscodsKEBeruRJeoQBVr3gDmNiAY/CIpgV4=; b=Ch4fCYBChiWPlzLorvU1Ms1Ks3fYJeZ0dFz/O12Bt0CfZOrPIOGBgtOSDScW+BD5H1 NUu461C4lF6NfMLRottbNIWr9lv9GHiTEY4jPrvl6LmCZi5MZdq569AWOgAv2E65u63a nKOOiX1DL3sFXahcq1Mxe8+87PWn0fTWoGwW8tg9X7XvC+R4Yjp9VFVi6YbUq0jpXTLV fjfna1skKmoQBhfRQ4rRCYEqy2W2zOCmGPhb0MW7z9L0kmKVTinSOaVoKAO6D1AXJTlJ XMffXD5qn9d9clmPtKlxPrAchUHQZcOJfsgg43Py1hAzlZBLBiKUEYZrt2r80ekK4n/o BmHw== X-Gm-Message-State: AOJu0Yw3I7mI18VKrzJBxx5xdRmsBbhWbMuPrVgPJmDLIKGDUVOfd1G4 jsyUFn64gXE8KlDpDPbPzc/2yw== X-Google-Smtp-Source: AGHT+IHd7cVXJhogUvC3glrvp7pAUhSure0jmrqLqudDE/+xPJB8KYVqinjtWOUMEijpoVix98IrwQ== X-Received: by 2002:a7b:c7cf:0:b0:404:730c:e7c1 with SMTP id z15-20020a7bc7cf000000b00404730ce7c1mr1201453wmk.15.1694781267285; Fri, 15 Sep 2023 05:34:27 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:aa19:4569:aeeb:c0d3]) by smtp.gmail.com with ESMTPSA id p3-20020a05600c204300b003fefaf299b6sm4553110wmg.38.2023.09.15.05.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:34:26 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson , Alexey Dobriyan , Peter Zijlstra Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/2] gpio: sim: fix an invalid __free() usage Date: Fri, 15 Sep 2023 14:34:22 +0200 Message-Id: <20230915123423.75948-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski gpio_sim_make_line_names() returns NULL or ERR_PTR() so we must not use __free(kfree) on the returned address. Let's rework the function so that it returns the size of the gpio-line-names array or a negative error code on failure. This way we know that the string array will either stay NULL or be set to a correct, kcalloc()'ed address. Fixes: 3faf89f27aab ("gpio: sim: simplify code with cleanup helpers") Reported-by: Alexey Dobriyan Closes: https://lore.kernel.org/all/07c32bf1-6c1a-49d9-b97d-f0ae4a2b42ab@p183/ Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-sim.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index 2b9d9e172d5d..b4e6d06d08a2 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -717,13 +717,14 @@ gpio_sim_device_config_live_show(struct config_item *item, char *page) return sprintf(page, "%c\n", live ? '1' : '0'); } -static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank, - unsigned int *line_names_size) +static int gpio_sim_make_line_names(struct gpio_sim_bank *bank, + char ***line_names) { unsigned int max_offset = 0; bool has_line_names = false; struct gpio_sim_line *line; - char **line_names; + int line_names_size; + char **names; list_for_each_entry(line, &bank->line_list, siblings) { if (line->offset >= bank->num_lines) @@ -743,26 +744,27 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank, if (!has_line_names) /* - * This is not an error - NULL means, there are no line - * names configured. + * This is not an error - 0 means, there are no line names + * configured. */ - return NULL; + return 0; - *line_names_size = max_offset + 1; + line_names_size = max_offset + 1; - line_names = kcalloc(*line_names_size, sizeof(*line_names), GFP_KERNEL); - if (!line_names) - return ERR_PTR(-ENOMEM); + names = kcalloc(line_names_size, sizeof(*line_names), GFP_KERNEL); + if (!names) + return -ENOMEM; list_for_each_entry(line, &bank->line_list, siblings) { if (line->offset >= bank->num_lines) continue; if (line->name && (line->offset <= max_offset)) - line_names[line->offset] = line->name; + names[line->offset] = line->name; } - return line_names; + *line_names = names; + return line_names_size; } static void gpio_sim_remove_hogs(struct gpio_sim_device *dev) @@ -866,8 +868,9 @@ gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank, struct fwnode_handle *parent) { struct property_entry properties[GPIO_SIM_PROP_MAX]; - unsigned int prop_idx = 0, line_names_size = 0; char **line_names __free(kfree) = NULL; + unsigned int prop_idx = 0; + int line_names_size; memset(properties, 0, sizeof(properties)); @@ -877,11 +880,11 @@ gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank, properties[prop_idx++] = PROPERTY_ENTRY_STRING("gpio-sim,label", bank->label); - line_names = gpio_sim_make_line_names(bank, &line_names_size); - if (IS_ERR(line_names)) - return ERR_CAST(line_names); + line_names_size = gpio_sim_make_line_names(bank, &line_names); + if (line_names_size < 0) + return ERR_PTR(line_names_size); - if (line_names) + if (line_names_size > 0) properties[prop_idx++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( "gpio-line-names", line_names, line_names_size); From patchwork Fri Sep 15 12:34:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 723373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 097BDEE6457 for ; Fri, 15 Sep 2023 12:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234836AbjIOMeg (ORCPT ); Fri, 15 Sep 2023 08:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234882AbjIOMef (ORCPT ); Fri, 15 Sep 2023 08:34:35 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A07A195 for ; Fri, 15 Sep 2023 05:34:30 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-401187f8071so14212775e9.0 for ; Fri, 15 Sep 2023 05:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694781268; x=1695386068; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a84fzKCzx4Lh1OZKpKQr9OcyKJOlraxzLNN52YI1hEE=; b=pV69U8x2y2E7TrkvPybl1AbIGU/vZH6heaNEpfqXM+BfiARsDzWrs/C2B5PGm2nYcs sHdfxMHbUiy6d1ItM/+COrdcDRcOGPqn73ScHkczyr4VVVOEKFJIZbRzfJXEc8ODdpDw P8N5dBfa+tncnmTfahvfKTXr9n+++0T4CqbXNz1l/vnlbIB0oEaAQHbEgh0TgvvMBoaG TVpaQjqxU6vvTzMO2Tk/6fV4nnF3sd7s7wPfth5HL/9e8ffJrMjoHmqtLUzVaMOT0QMV /xnkDT8Pp/C2Q1OthX73zDiFGfw+Iww54cVaTDvQ4lcmeIokXT5jZVITxp5GKdWI29XO aHRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694781268; x=1695386068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a84fzKCzx4Lh1OZKpKQr9OcyKJOlraxzLNN52YI1hEE=; b=Wzq1fbx8XyQNavObxFJrCkd1lQOjf1EAUgm5RGerrI2zB/FJMloFORBu0ufdhrDeAh /ZQZFF+j8xDwnfxk+xpPyq6i+E5pmC14FOGMAkgoG5JBirpcnugMsCU7z//wftDPzcpJ Wv4oOx50ZAT/lUi3yrZjGJUyJhzMh2IWG7HsI63HQnlzrskwXcwvy6WRPEt3ElO96MNE 7tnsVDgpCdyH4JHZ0tcj00s7pdKBLnW4wxXhkQ+5oG4XQP/3I123QOI8PwJbzE6cEJjV Jhhfcl2Me1i6DWFp+iT8S2/ifPUvA7dVhJUMDT+sAL1W1ojeatW5pheStprADrzJ40+t A9WA== X-Gm-Message-State: AOJu0YzTu/u/bXl6A2DMAPfwcJ+TNRZVH9b4dN3tRqCCZFJ8/TYtUOop YiVsOFy22nZ57xlC6iFlEQKRMey3FCVUjAahjEM= X-Google-Smtp-Source: AGHT+IHZpExjeLucadZx6gbnHX4mOvdY0Tl0Z1COO3eqQ76w2kvxj39S38pV2dQ0h8gGBO7/qj6cPQ== X-Received: by 2002:a05:600c:2218:b0:402:ea5c:1845 with SMTP id z24-20020a05600c221800b00402ea5c1845mr1191529wml.5.1694781268300; Fri, 15 Sep 2023 05:34:28 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:aa19:4569:aeeb:c0d3]) by smtp.gmail.com with ESMTPSA id p3-20020a05600c204300b003fefaf299b6sm4553110wmg.38.2023.09.15.05.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:34:27 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson , Alexey Dobriyan , Peter Zijlstra Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/2] gpio: sim: include a missing header Date: Fri, 15 Sep 2023 14:34:23 +0200 Message-Id: <20230915123423.75948-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230915123423.75948-1-brgl@bgdev.pl> References: <20230915123423.75948-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We're using various ERR macros from linux/err.h but the include is missing. Add it. Fixes: cb8c474e79be ("gpio: sim: new testing module") Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-sim.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index b4e6d06d08a2..d9d7df7bd387 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include