From patchwork Fri Nov 27 08:42:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 7711901 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D685A9F1D3 for ; Fri, 27 Nov 2015 08:42:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 039CB2060D for ; Fri, 27 Nov 2015 08:42:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 151D4205F9 for ; Fri, 27 Nov 2015 08:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754316AbbK0Im2 (ORCPT ); Fri, 27 Nov 2015 03:42:28 -0500 Received: from mail-lf0-f44.google.com ([209.85.215.44]:35356 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754295AbbK0ImZ (ORCPT ); Fri, 27 Nov 2015 03:42:25 -0500 Received: by lfdl133 with SMTP id l133so120823531lfd.2 for ; Fri, 27 Nov 2015 00:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=jSl9mb6RebaLurYFdTnQPFJM5j1Y460kSU+LHT5o33g=; b=Wc/5O/g7qTELIT0gqCjKeTp99Onvr4Cz/gUgVmZ4wNcxK0hgkRcuozWoezMyfyNEnN TPAyz22v8h+JmvG0NkTNUNwFLyMM6Vh0V4dKVn6MlbcgAheTHkBdRaEekW31dcbcUQFA K51TDtHaM53YCIZmImUnpdYc6Pl7K9M5ONyY0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jSl9mb6RebaLurYFdTnQPFJM5j1Y460kSU+LHT5o33g=; b=XgUajh3aS+keD3IZaQwYjtHRFRmi2nDrqGe8iUYX6KuR365XOnaQ5ikwG0mY8LLC4U 4CQ24v9VuVpi2ObnuPWXFgIL9CvzT91LEeepXq3OGdf05kOZnmX2Rtp9wWDc4Xx0mqCU pXkpxpfYfqK8/I0wnB6RlKnvnTFQo5DwuRsIP4TwbxzY7iedPzp9NZZN0DgQlkY4sPto /8y8xceVUXtNQKPbYlreOe9NqOhZsj+bmodV1rL3AILQ/bBxlz+LRtRiSKf4x6gW1+/L zpAoBIKH11wk30LIMRwI6ojcLWuauZpsVESYj4neZh/BSxR6to5w+Xv/GAZg6k7SiXVm PaMg== X-Gm-Message-State: ALoCoQlwasnau6CKBSRut9V7OJQYHkT4Dn5/PneiK5UW8VstelfA/YyRv9tdruyWpXBZZkLUdPW1 X-Received: by 10.112.147.9 with SMTP id tg9mr7264502lbb.38.1448613744219; Fri, 27 Nov 2015 00:42:24 -0800 (PST) Received: from garcia.imf.au.dk ([130.225.20.51]) by smtp.gmail.com with ESMTPSA id e63sm4821479lfe.5.2015.11.27.00.42.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Nov 2015 00:42:23 -0800 (PST) From: Rasmus Villemoes To: Chris Mason , Josef Bacik , David Sterba Cc: Rasmus Villemoes , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] btrfs: use kbasename in btrfsic_mount Date: Fri, 27 Nov 2015 09:42:11 +0100 Message-Id: <1448613732-2943-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.6.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is more readable. Signed-off-by: Rasmus Villemoes --- v2: make p const char* (thanks 0day). Original comment: I think the following strlcpy may be somewhat fragile since obviously ds->name and p overlap. It certainly relies on strlcpy doing a forward copy, and since different architectures can have their own strlcpy, that's hard to verify (and also won't necessarily continue to hold). Maybe if (p != ds->name) memmove(ds->name, p, strlen(p)+1); instead. fs/btrfs/check-integrity.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 0340c57bf377..d6fe77c5b4ac 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c @@ -95,6 +95,7 @@ #include #include #include +#include #include "ctree.h" #include "disk-io.h" #include "hash.h" @@ -3120,7 +3121,7 @@ int btrfsic_mount(struct btrfs_root *root, list_for_each_entry(device, dev_head, dev_list) { struct btrfsic_dev_state *ds; - char *p; + const char *p; if (!device->bdev || !device->name) continue; @@ -3136,11 +3137,7 @@ int btrfsic_mount(struct btrfs_root *root, ds->state = state; bdevname(ds->bdev, ds->name); ds->name[BDEVNAME_SIZE - 1] = '\0'; - for (p = ds->name; *p != '\0'; p++); - while (p > ds->name && *p != '/') - p--; - if (*p == '/') - p++; + p = kbasename(ds->name); strlcpy(ds->name, p, sizeof(ds->name)); btrfsic_dev_state_hashtable_add(ds, &btrfsic_dev_state_hashtable);