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; From patchwork Wed Oct 18 14:59:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 154945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4889810vqb; Wed, 18 Oct 2023 08:54:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFrAQVVd8SphjlY4BpPFgxDYFuoBnseN2V3ije0T4o1t3te6F+2XSk1yeKqvZL5/ujsjQfX X-Received: by 2002:a92:d182:0:b0:351:54db:c1bb with SMTP id z2-20020a92d182000000b0035154dbc1bbmr5945674ilz.0.1697644475961; Wed, 18 Oct 2023 08:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697644475; cv=none; d=google.com; s=arc-20160816; b=aWmUfAFT2xuABeFpQOxxKto1Bc2mTUK5JRx6vVkfj+N09JXOfr7DPJjVnL2Zv1djyz wsfBrcVq/lz4lx3UqwuR3jAUKXo88OszwpGmDz2cVCh0trNDysBY1yrXifdiIKO7QTiH 0Is5E1jb4xkzj/H32h3FTBdPNBoxhKZZ8DVWIym7f9TlrzzixduLhuJi1awBMREmzk4B OoWyUM481VnzwHRkMplARxs/zNwWI7PYFlqYoCSpdBLDUYqyK6jMLqzxHD3JV++FnKg/ osi0uVZ46dSsPC9RIxOiPtjyV3UGs2nVZ6Tp5Hv4TN3PmJJU4HDVcWtSLHUGOqRvGc9U rGoA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ME7VwGiUX8FDv8NUqhzWaD2coLdEoOcgkyqQONoPdNY=; fh=H9bixEXCdYplBzpDi3Nsw5bXK7WEYng7uXLBXnyIsto=; b=qns/v10w7//yGq6A9M5Gnz59vnw8/VMWmaxc5y6ZG4M9Uj+dYWN/mmWCDuHb8Fq6dx SXbUs7eJGQTvpMqyda6zvcgnfGpk/GxgLY1CPHRYZp+SzYVbH/zGrKFaQOx0IYNcuO23 pANzKeNuS4tipwoxnsuwenr89mz6DTOgsK/uqKtD4fX19HhxcNn3MIp4bzcn1/xhs9Tn ZMKAvanU+qeuTZzLYF0JRdAthIOfkg20I1zOnXF/6Wi1A/J7KXP+Ek8TANqAfmgEZpFL YGaCMK7T9BwrKtx623gpKYonFUCWZ7QFCDuS26Agg2fu8oTD8B5NfCHM8yE9WO2or1nc D7SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hr9zWDcp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q5-20020a056a00084500b006b4231ba465si4376307pfk.85.2023.10.18.08.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:54:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hr9zWDcp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 065C180D587B; Wed, 18 Oct 2023 08:54:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344066AbjJRPyW (ORCPT + 23 others); Wed, 18 Oct 2023 11:54:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232187AbjJRPyV (ORCPT ); Wed, 18 Oct 2023 11:54:21 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D580116 for ; Wed, 18 Oct 2023 08:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697644459; x=1729180459; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m++cbFcttJ557TMwzXL1cyFX9XiN4d5ABpIPjs4nz/c=; b=Hr9zWDcpNs1a5PgXvq8G93X45uq8w4XSc1wVp277Wh5Bnikv0rz9gDjR 0kUT9pje2Rigs/6CqTbVJq9wJ72pZ7rzW1c5VwI3cd7Gpm2VckH9hyqRL HF4r9kza2hZ9EUK6Gmt1AwtJ4yHW4W0vsj1uQJqlm9GrAqSNsMZFBcUwE PVkPCd3o+oqLNRp3l3iR0crqnn/y+sZB73KGiFeA8aWIul8XV+WD9YKya ihSIUvLZ56ZI604urDW7m3e24AeC75ERrHbCkCpVKFUC71/D06ctmP0Bf YbgMZ/FfY6XqgkBpQmGDtUG8ikCAFZGU3NVm4PZL8XddC1Z3DR+sFYXt3 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="389918969" X-IronPort-AV: E=Sophos;i="6.03,235,1694761200"; d="scan'208";a="389918969" 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="750135634" X-IronPort-AV: E=Sophos;i="6.03,235,1694761200"; d="scan'208";a="750135634" 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 17831192; Wed, 18 Oct 2023 17:59:51 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org Cc: Sudip Mukherjee , Greg Kroah-Hartman Subject: [resend, PATCH v1 2/2] parport: Drop even more unneeded NULL or 0 assignments Date: Wed, 18 Oct 2023 17:59:48 +0300 Message-Id: <20231018145948.1367648-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231018145948.1367648-1-andriy.shevchenko@linux.intel.com> References: <20231018145948.1367648-1-andriy.shevchenko@linux.intel.com> 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 18 Oct 2023 08:54:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780109254185952353 X-GMAIL-MSGID: 1780109254185952353 kzalloc() gives us a zeroed memory, no need to explicitly assing 0 or NULL or similar to the members of the data structure that has been allocated with the above mentioned API. Note, the initializstion of full_list member is not needed anymore as list_add_tail will rewrite the contents of the prev and next pointers. Signed-off-by: Andy Shevchenko --- drivers/parport/share.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/parport/share.c b/drivers/parport/share.c index 048a459ce4b0..e21831d93305 100644 --- a/drivers/parport/share.c +++ b/drivers/parport/share.c @@ -459,7 +459,6 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, sema_init(&tmp->ieee1284.irq, 0); tmp->spintime = parport_default_spintime; atomic_set(&tmp->ref_count, 1); - INIT_LIST_HEAD(&tmp->full_list); /* Search for the lowest free parport number. */ @@ -489,8 +488,6 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, /* assume the worst */ tmp->probe_info[device].class = PARPORT_CLASS_LEGACY; - tmp->waithead = tmp->waittail = NULL; - ret = device_register(&tmp->bus_dev); if (ret) { put_device(&tmp->bus_dev);