From patchwork Mon Oct 16 13:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 153401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3462896vqb; Mon, 16 Oct 2023 06:32:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIJJYxbMsOxP1e8Ljo6L8ZNPeRD5U69kRgvrSjky6dDY3sDNlIiQrHbKoBL6zzWopX0UQ6 X-Received: by 2002:a05:6602:3a05:b0:792:6be4:3dcb with SMTP id by5-20020a0566023a0500b007926be43dcbmr35924028iob.2.1697463151827; Mon, 16 Oct 2023 06:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697463151; cv=none; d=google.com; s=arc-20160816; b=XKN14tZNYF54qSVYh5swXLxlP/0nGAQ5DCQDZ/XV7ytiy6C69sOWhA3azepNADBPsq 5ZQmw+cB9wt/BFsYnXH74IHzDQJ+0PrZ6/Meb7hCgCxk1WbyEWyVuY39bwhuHuBKxxxw lSd3rdT0xfQOpJhlliKpS3goqK2056hnv5rHJW5rPLxI427aEm121VlVdJd4r+wo2g+W QbgZh5vB7VCzOHnsQIVmYAUbQNayYTKIyI4sSOabOYHUmXLjLJQOsEju8NekGNiW4MJ4 QJDE+y3wbB5Aa4t8MhyggqNQicBs/pLJGixwHxLCKS01DHc+Q/AxV19xuJ8qF9m6+qfc a7Lg== 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=t5JnZPzxGsiEvqdDtFioeXYIggckdh8BVKAekr+kMmU=; fh=2JBUIg4Hm6CI5OqXiiVJ9qu0u244D7Du+J73tUUcI/M=; b=P2PQbfYjD68XwQ+6mLnGEndbU4LRGezVM3JFbH/pK3Kka+8/Gxa0KNZF9CKSIbgQTP YjOs+xmh7c3mf9jQzTDPfawxGB9DhpdgpHlIR71QLmQNxLyBSijjBReXRrnPnn3/Lmd7 uVyMSqU5FCDQ9txirC7TsWOOUdFnDNSQgTHdGej2jvu+KehycSyOdD+4EwORMdVdK7yA bhvE5dSxN4viMaLbHLkppdy7E8nyeXT2WBxQcUmitUQIX/tNeWV19QcFpsis4iWP0hP3 NV0sjE3WvKX0AXPbxH2+K1GhaulztNjJxDLMFRVLDdWU5an1nnuivOfo1bRS1pEqYfHV z55Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NctZuDJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id e65-20020a636944000000b005b3cc1970e4si4277305pgc.560.2023.10.16.06.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 06:32:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NctZuDJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 ED9C38024DE6; Mon, 16 Oct 2023 06:32:28 -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 S233791AbjJPNcK (ORCPT + 18 others); Mon, 16 Oct 2023 09:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233745AbjJPNbt (ORCPT ); Mon, 16 Oct 2023 09:31:49 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA2EB18E for ; Mon, 16 Oct 2023 06:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697463104; x=1728999104; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gOFuCBEF7qDzKsVu/1gVwELNt4UpUHZQWLqV2968srU=; b=NctZuDJnGmkN7u+/MJgobLEHquP1IMcmNHPZzfj46GmkciWecKSPmHdQ rwNrFDYLP1EjkcUE3bZmlXUwF+00B0wSEIBNccf1p5yr0DM0I2+3GHA4c F/YxtFxLERbl6nBbKKeQ6UL54t1eW7I0YzRtUUjqNScDnkgQVwUxHGobh d0DSIBIg1UQS4iOvJ9NxSdz/1qcmzTda9cOFMmXUn0yQ0QACLuKK3x15E vS7f4Ci37PacAvT3FZ4dre+9o+om2BfwxbmdN3uI94niu48pDFsU2Kzh9 XpomAifLf190rglLpW2zYrVZjgKwu42zrldmQKxqauR6WCFXXpX33ZcKz Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="375892105" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="375892105" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 06:31:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="1002934887" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1002934887" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 16 Oct 2023 06:31:38 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 409A7BF; Mon, 16 Oct 2023 16:31:37 +0300 (EEST) From: Andy Shevchenko To: Luis Chamberlain , Joel Granados , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: Sudip Mukherjee , Greg Kroah-Hartman Subject: [resend, PATCH v1 1/3] parport: Use kasprintf() instead of fixed buffer formatting Date: Mon, 16 Oct 2023 16:31:33 +0300 Message-Id: <20231016133135.1203643-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231016133135.1203643-1-andriy.shevchenko@linux.intel.com> References: <20231016133135.1203643-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 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]); Mon, 16 Oct 2023 06:32:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779919121715440981 X-GMAIL-MSGID: 1779919121715440981 Improve readability and maintainability by replacing a hardcoded string allocation and formatting by the use of the kasprintf() helper. Signed-off-by: Andy Shevchenko --- drivers/parport/procfs.c | 53 +++++++--------------------------------- drivers/parport/share.c | 15 +++++------- include/linux/parport.h | 2 -- 3 files changed, 15 insertions(+), 55 deletions(-) diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c index 532d5cbbd344..bd388560ed59 100644 --- a/drivers/parport/procfs.c +++ b/drivers/parport/procfs.c @@ -32,13 +32,6 @@ #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ) #define PARPORT_MIN_SPINTIME_VALUE 1 #define PARPORT_MAX_SPINTIME_VALUE 1000 -/* - * PARPORT_BASE_* is the size of the known parts of the sysctl path - * in dev/partport/%s/devices/%s. "dev/parport/"(12), "/devices/"(9 - * and null char(1). - */ -#define PARPORT_BASE_PATH_SIZE 13 -#define PARPORT_BASE_DEVICES_PATH_SIZE 22 static int do_active_device(struct ctl_table *table, int write, void *result, size_t *lenp, loff_t *ppos) @@ -423,8 +416,7 @@ int parport_proc_register(struct parport *port) { struct parport_sysctl_table *t; char *tmp_dir_path; - size_t tmp_path_len, port_name_len; - int bytes_written, i, err = 0; + int i, err = 0; t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL); if (t == NULL) @@ -440,35 +432,23 @@ int parport_proc_register(struct parport *port) #endif /* IEEE 1284 support */ } - port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN); - /* - * Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT/devices. - * We calculate for the second as that will give us enough for the first. - */ - tmp_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len; - tmp_dir_path = kzalloc(tmp_path_len, GFP_KERNEL); + tmp_dir_path = kasprintf(GFP_KERNEL, "dev/parport/%s/devices", port->name); if (!tmp_dir_path) { err = -ENOMEM; goto exit_free_t; } - bytes_written = snprintf(tmp_dir_path, tmp_path_len, - "dev/parport/%s/devices", port->name); - if (tmp_path_len <= bytes_written) { - err = -ENOENT; - goto exit_free_tmp_dir_path; - } t->devices_header = register_sysctl(tmp_dir_path, t->device_dir); if (t->devices_header == NULL) { err = -ENOENT; goto exit_free_tmp_dir_path; } - tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len; - bytes_written = snprintf(tmp_dir_path, tmp_path_len, - "dev/parport/%s", port->name); - if (tmp_path_len <= bytes_written) { - err = -ENOENT; + kfree(tmp_dir_path); + + tmp_dir_path = kasprintf(GFP_KERNEL, "dev/parport/%s", port->name); + if (!tmp_dir_path) { + err = -ENOMEM; goto unregister_devices_h; } @@ -508,34 +488,22 @@ int parport_proc_unregister(struct parport *port) int parport_device_proc_register(struct pardevice *device) { - int bytes_written, err = 0; struct parport_device_sysctl_table *t; struct parport * port = device->port; - size_t port_name_len, device_name_len, tmp_dir_path_len; char *tmp_dir_path; + int err = 0; t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL); if (t == NULL) return -ENOMEM; - port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN); - device_name_len = strnlen(device->name, PATH_MAX); - /* Allocate a buffer for two paths: dev/parport/PORT/devices/DEVICE. */ - tmp_dir_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len + device_name_len; - tmp_dir_path = kzalloc(tmp_dir_path_len, GFP_KERNEL); + tmp_dir_path = kasprintf(GFP_KERNEL, "dev/parport/%s/devices/%s", port->name, device->name); if (!tmp_dir_path) { err = -ENOMEM; goto exit_free_t; } - bytes_written = snprintf(tmp_dir_path, tmp_dir_path_len, "dev/parport/%s/devices/%s", - port->name, device->name); - if (tmp_dir_path_len <= bytes_written) { - err = -ENOENT; - goto exit_free_path; - } - t->vars[0].data = &device->timeslice; t->sysctl_header = register_sysctl(tmp_dir_path, t->vars); @@ -548,9 +516,6 @@ int parport_device_proc_register(struct pardevice *device) kfree(tmp_dir_path); return 0; -exit_free_path: - kfree(tmp_dir_path); - exit_free_t: kfree(t); diff --git a/drivers/parport/share.c b/drivers/parport/share.c index 2d46b1d4fd69..8037bcd07bcf 100644 --- a/drivers/parport/share.c +++ b/drivers/parport/share.c @@ -438,7 +438,6 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, struct parport *tmp; int num; int device; - char *name; int ret; tmp = kzalloc(sizeof(struct parport), GFP_KERNEL); @@ -467,11 +466,6 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, atomic_set(&tmp->ref_count, 1); INIT_LIST_HEAD(&tmp->full_list); - name = kmalloc(PARPORT_NAME_MAX_LEN, GFP_KERNEL); - if (!name) { - kfree(tmp); - return NULL; - } /* Search for the lowest free parport number. */ spin_lock(&full_list_lock); @@ -487,11 +481,14 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, /* * Now that the portnum is known finish doing the Init. */ - sprintf(name, "parport%d", tmp->portnum = tmp->number); - tmp->name = name; + tmp->name = kasprintf(GFP_KERNEL, "parport%d", tmp->portnum); + if (!tmp->name) { + kfree(tmp); + return NULL; + } + dev_set_name(&tmp->bus_dev, tmp->name); tmp->bus_dev.bus = &parport_bus_type; tmp->bus_dev.release = free_port; - dev_set_name(&tmp->bus_dev, name); tmp->bus_dev.type = &parport_device_type; for (device = 0; device < 5; device++) diff --git a/include/linux/parport.h b/include/linux/parport.h index 999eddd619b7..fff39bc30629 100644 --- a/include/linux/parport.h +++ b/include/linux/parport.h @@ -180,8 +180,6 @@ struct ieee1284_info { struct semaphore irq; }; -#define PARPORT_NAME_MAX_LEN 15 - /* A parallel port */ struct parport { unsigned long base; /* base address */ From patchwork Mon Oct 16 13:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 153400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3462667vqb; Mon, 16 Oct 2023 06:32:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0kdyAosI+/z2MZUCKgaumemHDSiNIQkks19M0GDVkHiG85tgvPdQnEGPYj9QgWQpRjibZ X-Received: by 2002:a17:90b:1496:b0:27c:f88f:11a5 with SMTP id js22-20020a17090b149600b0027cf88f11a5mr16505839pjb.2.1697463133908; Mon, 16 Oct 2023 06:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697463133; cv=none; d=google.com; s=arc-20160816; b=e7RVf7g5aFP8lGmoVpemPgANcmvLL95a8oACQFL12onOilAANHzWsDjq3ry8rfcZke J6zuo5WRw1+p/NC4oPNDXDOe0YySh3nC3BlX0Gh8M0e16mjn9w2UkkdEp5u2ttla07Ic mC/krB189nXCYmGs4W2iXukLDW/btPJ/86NHIN7zdoxSYGRj2gwE0gu86iDYD6e2GuNk 5jr6eFhWRvXmF07W0pvW82btfMReOTNqgFxMpXNllUbEMdVCSfClQKMTuoaSWhD6N7yf PxLIOyFfQwN0oiXzyb47Zj5z8sVjihDffYlRrCNLZxIL8xkwU5Uba0nsAUBMH5yJFbFL m82g== 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=5eeKCGmD1ogfK8HTaFADoKhgXqcQE8rtC1VJ8TfoWgk=; fh=2JBUIg4Hm6CI5OqXiiVJ9qu0u244D7Du+J73tUUcI/M=; b=taeeqpzP0XSyt/ta6Y+V+YTwEHTMcfzmsPkBm5GntZ9eAnh+ZYqwxR5Kk+HP+awIfM RmwhLh4vnNl4JdQ9/WD8sPT58AfOBBSjspXKOCQpsj3pGusJmY2TPkDSN/l55uZW4Gen /uF9VwUBshNXNPc9vKdHZ0Wpg5SpKHY2h/uIPno1pmzQaQkQe0TfAp2NStNyoFrCmcLZ 03GKAxVI/rZbC9x0yOL/LkTYo3hjUiMze6FUOhrjI1avSiHScnZw6AQ04SPsjihjuqWt 7bQXsQXT8pX5Rme1pwTV1wfJAo6pr5PUCORWdhud7WmldFu3nH/ZdiQk67IysaQD1A/y oXAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=c4Obzebx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id 9-20020a630f49000000b0057ab7f46381si10148019pgp.76.2023.10.16.06.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 06:32:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=c4Obzebx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id C723880AD086; Mon, 16 Oct 2023 06:32:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233694AbjJPNb5 (ORCPT + 18 others); Mon, 16 Oct 2023 09:31:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233732AbjJPNbn (ORCPT ); Mon, 16 Oct 2023 09:31:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D165130 for ; Mon, 16 Oct 2023 06:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697463101; x=1728999101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4roMkrTkBxn5M4KrWiiG+UKPCzazaRQ4mwiu9FhhIQM=; b=c4Obzebx+22ek0tTzWqTdZ6SDlbcc4z010e8tysMxRi3YLNXIXXGRqv4 gJL0bQAGdxB+RqzG78A0fM9M/NMz+YLscXvf2gjHXhoh2UZWk86bx/i9A Mdp/zEZqGey2396OtzKkbrmlH6a+wmTMbu1y+jk7sVSW7CEMzik6SxJ/x QtDzaTTet6Iwnfo1ac0J8YXwz+x4Z6nAIVNWr0fLPbevlja2ioLeN1ifN 4j4Pxg9L7rLQn/DUhb1tsrGz4inu+qGz6xvLeu+2TvhDFiUzbkcQR1n5n SZulLF1eRGyL2EvN2cHu95BpinXrB7nQ0+bzkYfV5okYQy/+lzjvpqX+O w==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="375892089" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="375892089" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 06:31:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="1002934884" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1002934884" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 16 Oct 2023 06:31:38 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 566CE81C; Mon, 16 Oct 2023 16:31:37 +0300 (EEST) From: Andy Shevchenko To: Luis Chamberlain , Joel Granados , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: Sudip Mukherjee , Greg Kroah-Hartman Subject: [resend, PATCH v1 2/3] parport: Use list_for_each() helper Date: Mon, 16 Oct 2023 16:31:34 +0300 Message-Id: <20231016133135.1203643-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231016133135.1203643-1-andriy.shevchenko@linux.intel.com> References: <20231016133135.1203643-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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 06:32:08 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779919103415000480 X-GMAIL-MSGID: 1779919103415000480 Convert hard to read custom code to list_for_each(). No functional changes intended. Note, we may not use list_for_each_entry() as at the end of the list the iterator will point to an invalid entry and may not be dereferenced. Signed-off-by: Andy Shevchenko --- drivers/parport/share.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/parport/share.c b/drivers/parport/share.c index 8037bcd07bcf..38780f6a9119 100644 --- a/drivers/parport/share.c +++ b/drivers/parport/share.c @@ -469,9 +469,11 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, /* Search for the lowest free parport number. */ spin_lock(&full_list_lock); - for (l = all_ports.next, num = 0; l != &all_ports; l = l->next, num++) { + num = 0; + list_for_each(l, &all_ports) { struct parport *p = list_entry(l, struct parport, full_list); - if (p->number != num) + + if (p->number != num++) break; } tmp->portnum = tmp->number = num; From patchwork Mon Oct 16 13:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 153403 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3462944vqb; Mon, 16 Oct 2023 06:32:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0XaTLFWpXtivmessgvaCkSjU5tIt6Be1PS6lxVySDlZhuvDeQJbKyJ2G1JO1Wbu3YdYTg X-Received: by 2002:a05:6602:2a44:b0:792:9b50:3c3d with SMTP id k4-20020a0566022a4400b007929b503c3dmr42093201iov.1.1697463154787; Mon, 16 Oct 2023 06:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697463154; cv=none; d=google.com; s=arc-20160816; b=eONx3K1JYsVLML3cJrJ8QguXF6eiI/cb0gQ5Q5XXm2JcJZbNra3rJ1KkEhvN9forJr vIUg8Kl2TqZsaC+eKmPWtBLGnDwc5TM7SXiwVSfcss36vlZ48xUJW+dfOWhJqHXkUfzs 0lTNlpgVoTF6tUSxKPvDCpPfZCmy1yqo363SCBpAx8aTPteNkyARSGWUITZ6LniIA5KU OVOFD0s0o8XJ+OtlthUaITDTc7wTEhL/NqtHaTDzZLuufZESBNoN77tq3E6UpihWPare /Mpn7yf95dXkqf/dziYNlypVKRtHgevfyRqL79BrJIpfGCDqlQ8sOse+9qB8akPIoVW1 5mXA== 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=OfJ44MLqQGAMiJh1/T4KhpBe1qm9TWK7F+GIsy9rZK4=; fh=2JBUIg4Hm6CI5OqXiiVJ9qu0u244D7Du+J73tUUcI/M=; b=PlkDawEiFOQbMsB+P3ldWvL0g8uPwOpgL9oqX98H1Am2fqIexXXnGC2wJWyRHfmILm w0pL4UWX+DpaF9wQJTg2Sc+fMtkGPO/6zeQX33pGGNfCizcIF8RZVh1KoR3eDeELMS6b JTn/eohoukV2sy5gI6NAfHtwEG3xUNLkVOcSEJkfEFkvUAEpHj8Nj7LuP1dQCSP/amI1 2U9BkBV0S6y3Wtql2rKRPWXbZXPU3922iMkRjrOVH8nG3AgqJX9PkOXAxRoZMhg+K1Qj /lOaxmcpsmaOtECTP/HzWN30Ee0wbqAU8ChpZ8C19pOy683YUPT8lT1gZ1rnpW4WXLN2 Aduw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FICsEJgp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id b9-20020a63d809000000b005637962e15esi10423950pgh.603.2023.10.16.06.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 06:32:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FICsEJgp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 445EA804AD82; Mon, 16 Oct 2023 06:32:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233631AbjJPNcA (ORCPT + 18 others); Mon, 16 Oct 2023 09:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233685AbjJPNbt (ORCPT ); Mon, 16 Oct 2023 09:31:49 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2617181 for ; Mon, 16 Oct 2023 06:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697463102; x=1728999102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cdkuTO8u3rbVQRk8x8e3eLaDQYXu7b3sptU0SE6tXHc=; b=FICsEJgp9MRABfRfCapKVMFU7ahAwT4XPR+8WonqNzRaGtfDVZkzgsmc I6uLsKJ6xn88RIfYqLP/e6HR0lUaoGqGkaKcPq8zARkn6p1ptI6Cjt0N9 Dgstcq2YqHcp5AB6OfIaYR0U0IMoymIxEot7TejeqUnQWXcUWVHC6/LCn WEVvsWJcmKKSofYPpEVdyF3UNqPLulHeRmGI6vpM2p7V7djBpBeKtCkdZ zzbCKAysFDhhvuVeayUQ+pYdT2uzZbozuXj0SaH2pRdyZ7u0dwbths89u ++CAEWP4vZfa1MHDYUDEDJTKhkJUUYMhbexoYEy9lndiwubfS0+BdGJpJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="375892095" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="375892095" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 06:31:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="1002934885" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1002934885" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 16 Oct 2023 06:31:38 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5BF63385; Mon, 16 Oct 2023 16:31:37 +0300 (EEST) From: Andy Shevchenko To: Luis Chamberlain , Joel Granados , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: Sudip Mukherjee , Greg Kroah-Hartman Subject: [resend, PATCH v1 3/3] parport: Drop unneeded NULL or 0 assignments Date: Mon, 16 Oct 2023 16:31:35 +0300 Message-Id: <20231016133135.1203643-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231016133135.1203643-1-andriy.shevchenko@linux.intel.com> References: <20231016133135.1203643-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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 06:32:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779919125411641994 X-GMAIL-MSGID: 1779919125411641994 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. Signed-off-by: Andy Shevchenko --- drivers/parport/share.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/parport/share.c b/drivers/parport/share.c index 38780f6a9119..a9a9cb0477ea 100644 --- a/drivers/parport/share.c +++ b/drivers/parport/share.c @@ -449,13 +449,9 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, tmp->irq = irq; tmp->dma = dma; tmp->muxport = tmp->daisy = tmp->muxsel = -1; - tmp->modes = 0; INIT_LIST_HEAD(&tmp->list); - tmp->devices = tmp->cad = NULL; - tmp->flags = 0; tmp->ops = ops; tmp->physport = tmp; - memset(tmp->probe_info, 0, 5 * sizeof(struct parport_device_info)); rwlock_init(&tmp->cad_lock); spin_lock_init(&tmp->waitlist_lock); spin_lock_init(&tmp->pardevice_lock);