From patchwork Tue Nov 21 00:12:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10067569 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 107E66056A for ; Tue, 21 Nov 2017 00:13:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E84F329351 for ; Tue, 21 Nov 2017 00:13:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA7CC29371; Tue, 21 Nov 2017 00:13:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AE9E29343 for ; Tue, 21 Nov 2017 00:13:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751526AbdKUANR (ORCPT ); Mon, 20 Nov 2017 19:13:17 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35354 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751212AbdKUANQ (ORCPT ); Mon, 20 Nov 2017 19:13:16 -0500 Received: by mail-wr0-f194.google.com with SMTP id w95so9731495wrc.2 for ; Mon, 20 Nov 2017 16:13:16 -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=0QKgy2pCyjctuIqEqtsiFlZxfopw4sKSgxxnZlN/YHA=; b=MQDHqw4+qByRslZktAZy5btH5App38YJhXIGIcXMQHwZEYgTohouyVpCTzyXGcbcAi sFts1XrlkOq+rDfeO3ZW43Nk98OGlGIVfopxxMGfDZnNBzK/SchB/O0XW4eOLuxuEO8c kVfCYQ40zXxmG1n+FJ41cbctp1etruyNtT1bY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0QKgy2pCyjctuIqEqtsiFlZxfopw4sKSgxxnZlN/YHA=; b=BMvhV2crtvXKvW+kFI+v31nUEZicfnpRn6785mQbX+gTW1ZvBUolJJ7M4kP0lfQ5Zk 4Cm3ojyv+QNS7KLxASfel0/Bww+GfEZZIfjiiE7XE5vaDFlAVDt4uDRidK6QvI3m3rRw aTGbqyfDxK8tp4pbzEoZ73qhT1VTIeUoiPwwRKHwCPNgQCOhgmWjA+MoDGXHLBdBq5of 6WYWa1Aoo+l7EIB/YSEyUfnUTOKw2iNEmG7z/UDm+dgdq7el02ki1xYApKumF7xMAGpJ JoLOKFrcMurpX8PM0/cApQXG6d8qY+f+OJl8yiLgq7XXAwakjqFrNXBrFSw6FR0S5oQM lvag== X-Gm-Message-State: AJaThX5+QFMXgEoX1W15Pa79XN6Q1Vkzp7BEAgkSucWACggYKabIGolv 1qCvJzYQfk3aITCnvpswHIDSVbmY X-Google-Smtp-Source: AGs4zMb0klg5Vf3vTi1lq9NmpRQPJculhwns9K2iVgxrDk8uL3atBSzcxDU7rbcqanyyxuilN7pIHg== X-Received: by 10.223.164.20 with SMTP id d20mr14071909wra.103.1511223195352; Mon, 20 Nov 2017 16:13:15 -0800 (PST) Received: from wildmoose.dk ([2a01:488:66:1000:57e6:57d1:0:1]) by smtp.gmail.com with ESMTPSA id x75sm14598640wme.29.2017.11.20.16.13.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 16:13:14 -0800 (PST) From: Rasmus Villemoes To: "Nicholas A. Bellinger" Cc: Rasmus Villemoes , Rasmus Villemoes , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] target-core: don't use "const char*" for a buffer that is written to Date: Tue, 21 Nov 2017 01:12:43 +0100 Message-Id: <20171121001244.8026-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.11.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rasmus Villemoes iscsi_parse_pr_out_transport_id launders the const away via a call to strstr(), and then modifies the buffer (writing a nul byte) through the return value. It's cleaner to be honest and simply declare the parameter as "char*", fixing up the call chain, and allowing us to drop the cast in the return statement. Amusingly, the two current callers found it necessary to cast a non-const pointer to a const. Signed-off-by: Rasmus Villemoes --- drivers/target/target_core_fabric_lib.c | 6 +++--- drivers/target/target_core_internal.h | 2 +- drivers/target/target_core_pr.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c index 508da345b73f..71a80257a052 100644 --- a/drivers/target/target_core_fabric_lib.c +++ b/drivers/target/target_core_fabric_lib.c @@ -273,7 +273,7 @@ static int iscsi_get_pr_transport_id_len( static char *iscsi_parse_pr_out_transport_id( struct se_portal_group *se_tpg, - const char *buf, + char *buf, u32 *out_tid_len, char **port_nexus_ptr) { @@ -356,7 +356,7 @@ static char *iscsi_parse_pr_out_transport_id( } } - return (char *)&buf[4]; + return &buf[4]; } int target_get_pr_transport_id_len(struct se_node_acl *nacl, @@ -405,7 +405,7 @@ int target_get_pr_transport_id(struct se_node_acl *nacl, } const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg, - const char *buf, u32 *out_tid_len, char **port_nexus_ptr) + char *buf, u32 *out_tid_len, char **port_nexus_ptr) { u32 offset; diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 18e3eb16e756..cada158cf1c2 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -101,7 +101,7 @@ int target_get_pr_transport_id(struct se_node_acl *nacl, struct t10_pr_registration *pr_reg, int *format_code, unsigned char *buf); const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg, - const char *buf, u32 *out_tid_len, char **port_nexus_ptr); + char *buf, u32 *out_tid_len, char **port_nexus_ptr); /* target_core_hba.c */ struct se_hba *core_alloc_hba(const char *, u32, u32); diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index dd2cd8048582..09941d1ae6c1 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -1597,7 +1597,7 @@ core_scsi3_decode_spec_i_port( dest_rtpi = tmp_lun->lun_rtpi; i_str = target_parse_pr_out_transport_id(tmp_tpg, - (const char *)ptr, &tid_len, &iport_ptr); + ptr, &tid_len, &iport_ptr); if (!i_str) continue; @@ -3285,7 +3285,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key, goto out; } initiator_str = target_parse_pr_out_transport_id(dest_se_tpg, - (const char *)&buf[24], &tmp_tid_len, &iport_ptr); + &buf[24], &tmp_tid_len, &iport_ptr); if (!initiator_str) { pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate" " initiator_str from Transport ID\n");