From patchwork Wed Oct 18 14:59:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 154946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4889850vqb; Wed, 18 Oct 2023 08:54:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELbAg5khre9YgVho/QAtyM4e4wt1VphGVR3Nf42SQx75osXkZoWLq0lYkMSskmGc5Swoc3 X-Received: by 2002:a05:6870:3123:b0:1ea:972:d2b6 with SMTP id v35-20020a056870312300b001ea0972d2b6mr6318101oaa.3.1697644480434; Wed, 18 Oct 2023 08:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697644480; cv=none; d=google.com; s=arc-20160816; b=jjYwCn97ECbeJyZhmaZcZj2VoQ94G9ga7KsJj3qv7mWPnL8hajUoC5Om6dMB0XBaTK I16sEnYTawP335/k1H16GikSkk2K1QZa8N3Zzotvchm1krndx1pQ78KpOfeLqbpbiY3+ vCUpl73pT55METb2Ev5UAyds+R4ZJ4gzzjKb0wBZWsSoTIfLgqbnTC1ungtyk8ELEe4R AIuhsVZxr5NmV5EahnKDCqVDgruD1v4WU6tTnhNyXFe5AWAvKb2MkKE8PIdYFIY6zk/6 KzxJU0+Vvf1Uugme20Mzkl7YkV1aQs8JaV2cVoSVyeGtVSyLUOFDWjtiPYke4Hj1lpit 6WDA== 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:dkim-signature; bh=/Xk6Y6L1OCcuJHKKRuxdccdNQhai2X9YDUY8Zz3xCSs=; fh=nyWh/9jmLm7lfsU7uwnNrwYHH11qZkugY+RApJePzkY=; b=ox/BiPl4IOW2DH9nl9WLc+K3obkJo7tJ7QvG4o4Fgy2XQKdsoIUBN6cddr3gOGIIbt BVXeEOkwkoC/8A8mgZdv74NabTkzLUngCpjGFKy0uOTllQ4sWsc1is4i5HgOws0ABh9e y9HiPo82Ec1a8JVqUPT1KjRfvAB92TGzKB+yVANAGnxoZvBSzB2Xk8kea12rAWksRnd0 kqiIZKCxuBigemIIkdlfcZPg/tWSWhDU0v22DPsikaaHezg0JNnCE8rxjfiVYa97Gc5n Z2+P/OtV/+WQZO3zx6ce0JWiu6/J4DzW+WttEjW92+K2dZ9ThHNFSVNKBNegteGJUdP7 JuTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gSa0GCvH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id e124-20020a636982000000b005af979066c0si2412649pgc.306.2023.10.18.08.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:54:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gSa0GCvH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 4D67981E141B; Wed, 18 Oct 2023 08:54:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232506AbjJRPy2 (ORCPT + 23 others); Wed, 18 Oct 2023 11:54:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232504AbjJRPy0 (ORCPT ); Wed, 18 Oct 2023 11:54:26 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AEAE118 for ; Wed, 18 Oct 2023 08:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697644460; x=1729180460; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=efWEYbNSPrNMZw5ETi6i0i2V6S/DkOB90d/QiicL5io=; b=gSa0GCvHzAyGQXBAvp+B0DaoB2AkJQFOWyw+lrcBaHRkoThQbjD/L4zs jTIX/Pk7gS/IrRAodiDcdbv9H+CPocwRr4fuWiRXgOzotuEIVtKRj2Pwk FxyG9gcamp5vN14E/EuA+QHzDAmwQYiIo80TBdElthHYqZyqClmwzYse4 tLlZNnky8FROyuScUKQ6nrxngRiuhlTZRPlWOtJn74RubD2YXhC7Ca/lE 6Un74e2aJkn2kry9S1p2AG/8LL3kgzMi6QqIR4fXhYrEncDWgCWz/OwWe PBJ9zqS86AlYL6dNTbFSbh4I8VuWdmeZTD9+nfM3dVQeXbg0LaojU4/nC g==; X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="389918974" X-IronPort-AV: E=Sophos;i="6.03,235,1694761200"; d="scan'208";a="389918974" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 08:54:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="750135638" X-IronPort-AV: E=Sophos;i="6.03,235,1694761200"; d="scan'208";a="750135638" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 18 Oct 2023 08:54:17 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8136317F; Wed, 18 Oct 2023 17:59:50 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org Cc: Sudip Mukherjee , Greg Kroah-Hartman , kernel test robot , Dan Carpenter Subject: [resend, PATCH v1 1/2] parport: Clean up resources correctly when parport_register_port() fails Date: Wed, 18 Oct 2023 17:59:47 +0300 Message-Id: <20231018145948.1367648-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 08:54:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780105804526982554 X-GMAIL-MSGID: 1780109258261779645 The smatch warns about uncleaned resources in case the parport_register_port() fails: parport_register_port() warn: '&tmp->full_list' not removed from list This is indeed an issue introduced when converting code to use kasprintf(). However, the whole kasprintf() dance in this case is not needed as dev_set_name() can handle the formatted input and produces the same result. So, the solution is to delegate name forming to the dev_set_name() and make device_register() error path to deal with error handling (via put_device() call). Fixes: 8d8ae17eb0de ("parport: Use kasprintf() instead of fixed buffer formatting") Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202310180809.hepZB9k6-lkp@intel.com/ Signed-off-by: Andy Shevchenko --- drivers/parport/share.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/parport/share.c b/drivers/parport/share.c index a9a9cb0477ea..048a459ce4b0 100644 --- a/drivers/parport/share.c +++ b/drivers/parport/share.c @@ -361,7 +361,6 @@ static void free_port(struct device *dev) kfree(port->probe_info[d].description); } - kfree(port->name); kfree(port); } @@ -479,16 +478,13 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, /* * Now that the portnum is known finish doing the Init. */ - tmp->name = kasprintf(GFP_KERNEL, "parport%d", tmp->portnum); - if (!tmp->name) { - kfree(tmp); - return NULL; - } - dev_set_name(&tmp->bus_dev, tmp->name); + dev_set_name(&tmp->bus_dev, "parport%d", tmp->portnum); tmp->bus_dev.bus = &parport_bus_type; tmp->bus_dev.release = free_port; tmp->bus_dev.type = &parport_device_type; + tmp->name = dev_name(&tmp->bus_dev); + for (device = 0; device < 5; device++) /* assume the worst */ tmp->probe_info[device].class = PARPORT_CLASS_LEGACY;