Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp4182382rdh; Fri, 29 Sep 2023 13:55:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGirSaFC6+FmWN6EFOwUTXR4OzA//PQbX0qkp0oTLGVPQmfAAwwCDAsDCYR4z5JWPtK0dYv X-Received: by 2002:a05:6808:6185:b0:3a7:45e0:c0eb with SMTP id dn5-20020a056808618500b003a745e0c0ebmr5758691oib.24.1696020912251; Fri, 29 Sep 2023 13:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696020912; cv=none; d=google.com; s=arc-20160816; b=CI+ddgyJLBYmmWbTk4JnWMX16ahRPoOSulXvIUxws7pAAdDn4HUNIWRReXFje9M6xi z29uO0hlioHFsVtZMt2TIndhoC03C7cRkDHm6kyY8hdAyUANLyXL775HzhTAZR1VGdWk 2BUjHWrh2/ybxuRysiyFvb+xeK+6ipLdwOqH2oI/8KwnZJOTIwg1i44J+0BFZfEz3mQ7 0kS1hIq0NB5TbzGYXyAO5CfpaMiCsuSq2L5PZLc62ce1YT8rd03C6p9XSH5xxaTFpeTf Muo41Ontz+K6Fr5EfXJwBrwS5OFM750uhxqp6DLmT54tDRN14qwASSdMBi1VFS4cLTxH /s7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=QA2f5lgwTTwn9iY6UG1Mu764p2rQ3AQ0k6JCDenrBcA=; fh=OsxpHFVO0TTWpkd9nz9iIoXNJG/cbfzAlmsmMnvz/wI=; b=GDlvgGYsUwT+qfQez1IWQ/iN1/ttIbLQ4kICvzrsg0yeMpG5nKi4eyLDBQ3xO+D5oq Qi+gBYqlefuOlya+xqq28miGaaUws8pls7rPr7x/Cw6+vZpE8hsD8nGc/Wss2uPUYH9S tWP8350hEQi5Vc3+HnQXqX1XaFkDoJeQBpJIiOMTY+/uIppb3F5PEZcW/xyGImo5bXEn VnsZPUCVtxEUTzVAVUMEXBIcCfd2PEGzDq/EIaL4vYhZIdccc6ocEK6UQ3gIlbbUXIz7 qYZlQjS2c8PymvKVJuKhuQRCJc/fVomuR7mz99cZnyQrUFQeMgIouLFSgy0gT2p5Jcwp 3dIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=B3GaBSWb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b005855e5e2f98si6934896pgv.75.2023.09.29.13.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 13:55:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=B3GaBSWb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C136E8051B43; Fri, 29 Sep 2023 09:30:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233572AbjI2Qa0 (ORCPT + 99 others); Fri, 29 Sep 2023 12:30:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233054AbjI2QaZ (ORCPT ); Fri, 29 Sep 2023 12:30:25 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67381199 for ; Fri, 29 Sep 2023 09:30:22 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-522bd411679so17920043a12.0 for ; Fri, 29 Sep 2023 09:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696005021; x=1696609821; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=QA2f5lgwTTwn9iY6UG1Mu764p2rQ3AQ0k6JCDenrBcA=; b=B3GaBSWbUTjIz701Evcjh9HdU5pqjkQfmi3hITxg2VIFpqCKsdhe+CtqPVYFEhsCXu TdZYPrwj4pjT4bC7C9paUySMX0H5PT+r0UYHnACXgZoUPo74gRwfTMSfGdTtJgO9JxQk dwafoG/9+OwEkDqt3NmdG1Z8d0eKxFyCLg/31IOPpAdB5a5fMucMCMFUmG50BWQ788N9 jfIdx8dmCm4mnebPRjYthIvyeJpiny5e/SS8QmWOBC2gHl7t28xNh2D4vGpd1daIjVf0 F4vmR62vNyhSbXRdr12jEFyDLH3wvzc+fauMr7DdWY87GmFlcKP9Je9ejAUXRCzMRmxY PgMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696005021; x=1696609821; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QA2f5lgwTTwn9iY6UG1Mu764p2rQ3AQ0k6JCDenrBcA=; b=UyPv/LZ9vkawNUj3zX0ayUnannmkD+i+ecYoBmLaiSmXNl5VUGG3AYQZVdcGHpw72T oQOTnEzeh5AF78hltGOt5PgI7mz4cKlnga1S502uXQQNN6ZRSARzHTvN9dJhTGmavLpv WiFEQM7pFK+9LZ+VS8Mo5SsjUL5qwiWTCCgF/3mmtjkOImzeQQLMCWReur5pGaIiC6CX QW8DLJ8CaqvAblhB6FwbhLYfVr25SPka/2BLK28NLf7NcfOrPwqa7Df+vKOXVwrAbl2R RKno7eZIwFCeNRHyMVSACE6DT+MP98FZsnxvZ/URu758VeihktgBdr857exYFwqQSFph 1xZg== X-Gm-Message-State: AOJu0Yxkz9/53gIAkINzou6aokKGPynmSl9YgCSB33Nmj7p3RcUtxF5M TLsUlL5fhOezij85ep4YxsVCjcqw8g== X-Received: by 2002:aa7:db50:0:b0:52b:db31:3c5c with SMTP id n16-20020aa7db50000000b0052bdb313c5cmr4351153edt.0.1696005020570; Fri, 29 Sep 2023 09:30:20 -0700 (PDT) Received: from p183 ([46.53.252.219]) by smtp.gmail.com with ESMTPSA id fi9-20020a056402550900b00533bab9d9f1sm8804430edb.1.2023.09.29.09.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 09:30:20 -0700 (PDT) Date: Fri, 29 Sep 2023 19:30:18 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] proc: use initializer for clearing some buffers Message-ID: <3821d3a2-6e10-4629-b0d5-9519d828ab72@p183> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 29 Sep 2023 09:30:34 -0700 (PDT) Save LOC by using dark magic of initialisation instead of memset(). Those buffer aren't passed to userspace directly so padding is not an issue. Signed-off-by: Alexey Dobriyan --- fs/proc/base.c | 16 ++++++---------- fs/proc/task_mmu.c | 11 +++-------- 2 files changed, 9 insertions(+), 18 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1153,11 +1153,10 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) static ssize_t oom_adj_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { - char buffer[PROC_NUMBUF]; + char buffer[PROC_NUMBUF] = {}; int oom_adj; int err; - memset(buffer, 0, sizeof(buffer)); if (count > sizeof(buffer) - 1) count = sizeof(buffer) - 1; if (copy_from_user(buffer, buf, count)) { @@ -1213,11 +1212,10 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf, static ssize_t oom_score_adj_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { - char buffer[PROC_NUMBUF]; + char buffer[PROC_NUMBUF] = {}; int oom_score_adj; int err; - memset(buffer, 0, sizeof(buffer)); if (count > sizeof(buffer) - 1) count = sizeof(buffer) - 1; if (copy_from_user(buffer, buf, count)) { @@ -1358,13 +1356,13 @@ static ssize_t proc_fault_inject_write(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { struct task_struct *task; - char buffer[PROC_NUMBUF]; + char buffer[PROC_NUMBUF] = {}; int make_it_fail; int rv; if (!capable(CAP_SYS_RESOURCE)) return -EPERM; - memset(buffer, 0, sizeof(buffer)); + if (count > sizeof(buffer) - 1) count = sizeof(buffer) - 1; if (copy_from_user(buffer, buf, count)) @@ -1509,11 +1507,10 @@ sched_autogroup_write(struct file *file, const char __user *buf, { struct inode *inode = file_inode(file); struct task_struct *p; - char buffer[PROC_NUMBUF]; + char buffer[PROC_NUMBUF] = {}; int nice; int err; - memset(buffer, 0, sizeof(buffer)); if (count > sizeof(buffer) - 1) count = sizeof(buffer) - 1; if (copy_from_user(buffer, buf, count)) @@ -1666,10 +1663,9 @@ static ssize_t comm_write(struct file *file, const char __user *buf, { struct inode *inode = file_inode(file); struct task_struct *p; - char buffer[TASK_COMM_LEN]; + char buffer[TASK_COMM_LEN] = {}; const size_t maxlen = sizeof(buffer) - 1; - memset(buffer, 0, sizeof(buffer)); if (copy_from_user(buffer, buf, count > maxlen ? maxlen : count)) return -EFAULT; --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -849,9 +849,7 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss, static int show_smap(struct seq_file *m, void *v) { struct vm_area_struct *vma = v; - struct mem_size_stats mss; - - memset(&mss, 0, sizeof(mss)); + struct mem_size_stats mss = {}; smap_gather_stats(vma, &mss, 0); @@ -877,7 +875,7 @@ static int show_smap(struct seq_file *m, void *v) static int show_smaps_rollup(struct seq_file *m, void *v) { struct proc_maps_private *priv = m->private; - struct mem_size_stats mss; + struct mem_size_stats mss = {}; struct mm_struct *mm = priv->mm; struct vm_area_struct *vma; unsigned long vma_start = 0, last_vma_end = 0; @@ -893,8 +891,6 @@ static int show_smaps_rollup(struct seq_file *m, void *v) goto out_put_task; } - memset(&mss, 0, sizeof(mss)); - ret = mmap_read_lock_killable(mm); if (ret) goto out_put_mm; @@ -1246,14 +1242,13 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { struct task_struct *task; - char buffer[PROC_NUMBUF]; + char buffer[PROC_NUMBUF] = {}; struct mm_struct *mm; struct vm_area_struct *vma; enum clear_refs_types type; int itype; int rv; - memset(buffer, 0, sizeof(buffer)); if (count > sizeof(buffer) - 1) count = sizeof(buffer) - 1; if (copy_from_user(buffer, buf, count))