From patchwork Fri Oct 5 03:47:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 979272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42RG1T2kdNz9s7W for ; Fri, 5 Oct 2018 13:47:57 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SQJUAQVz"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42RG1T0y8GzF3JM for ; Fri, 5 Oct 2018 13:47:57 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SQJUAQVz"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SQJUAQVz"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42RG1N4g2QzDqdv for ; Fri, 5 Oct 2018 13:47:52 +1000 (AEST) Received: by mail-pf1-x442.google.com with SMTP id s5-v6so4399889pfj.7 for ; Thu, 04 Oct 2018 20:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=aJaIFKPVrb+4nfLaP+93pDn7clVPfHUbm5qZki7EcKQ=; b=SQJUAQVzqikccY2e3t1BgJNaQ44jZGbT/C9EiwY71TnlwtcMW53TwD8y0Y0LPUP6M4 mmcJ/YAxfZSPCf/POGxbex/2Wj0w5h1LDDvC/SRSODm5dbHykjCvtnw+bQ/fRYcsYMqX m+JCAYzAWgGTwdMkVADVDaKfpqUVSHyYQx/TeC95ixlWfoV80ryf2uEErM3vOruCIFji 4fiTn8qtd7X/Gqwvxf4FRUfHHTA3KrT4/BKdT7QekVqz+i8X/FelAfsPur/c3d9X5NzV 8W+s9gyXyyqdCrUfgCSWG3klR0fnaOSZvd2nGAee88m0zjg7hMWlAIBQEOGnESFcfZvU 9mtA== 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=aJaIFKPVrb+4nfLaP+93pDn7clVPfHUbm5qZki7EcKQ=; b=g0E5/xGeTo1G0M3LINot6IfSVfoKRTObB6cNnsEIa8Z360XpjxBXhCbQffVMjDEgox JBXK9WktAnfDEpFwFE6riOxQaL+4rNDZDmlFSMQ2XCjw8zUdtdqEqPbBSWtENL9n3kV1 HpoZXQal6yq/SosB/tI9Z20aEK9PbrFMAL+WQrw0aHULYINJoBbaDojAx1PAxQ32Htmg 66mVJdE1evuOD3Zu9QJdyixNc7Sj9866yy+gykYmaSSRFxlOR1iatmmexUfSY9IuN93C 02GZ8pdAR8A/VHR0yCfa6IBQHQF42IDMaBhpxnUAFPwpvrVGnbBbyTMB8RMg+GVwWcZZ xCow== X-Gm-Message-State: ABuFfojaflErMnqKOOf5PC7WArLJlaGeH/Hk0wkriSqU3BsnTJbjZZHy 6hGXTbjTb3qlJGSpByAsOL/Qtc6I5tQ= X-Google-Smtp-Source: ACcGV62tUj8XzbMXjgVSLSTf4nYhG+grN4bVh6YwVP2i++7O2bYhSxMGHvszV4IX2eUrc0/8OVj6rw== X-Received: by 2002:a65:664e:: with SMTP id z14-v6mr8119344pgv.347.1538711270885; Thu, 04 Oct 2018 20:47:50 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id f25-v6sm7980222pfn.177.2018.10.04.20.47.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Oct 2018 20:47:50 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org Date: Fri, 5 Oct 2018 13:47:42 +1000 Message-Id: <20181005034742.1910-1-rashmica.g@gmail.com> X-Mailer: git-send-email 2.14.4 Subject: [Pdbg] [PATCH] libpdbg/adu: always release the adu lock before returning from an error X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Rashmica Gupta --- libpdbg/adu.c | 29 ++++++++++++++++------------- libpdbg/operations.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libpdbg/adu.c b/libpdbg/adu.c index 27049b7..375deda 100644 --- a/libpdbg/adu.c +++ b/libpdbg/adu.c @@ -237,6 +237,7 @@ static int adu_reset(struct adu *adu) static int p8_adu_getmem(struct adu *adu, uint64_t addr, uint64_t *data, int ci) { uint64_t ctrl_reg, cmd_reg, val; + int rc = 0; CHECK_ERR(adu_lock(adu)); @@ -248,25 +249,25 @@ static int p8_adu_getmem(struct adu *adu, uint64_t addr, uint64_t *data, int ci) ctrl_reg = SETFIELD(P8_FBC_ALTD_TTYPE, ctrl_reg, P8_TTYPE_DMA_PARTIAL_READ); ctrl_reg = SETFIELD(P8_FBC_ALTD_TSIZE, ctrl_reg, 8); - CHECK_ERR(pib_read(&adu->target, P8_ALTD_CMD_REG, &cmd_reg)); + CHECK_ERR_GOTO(out, rc = pib_read(&adu->target, P8_ALTD_CMD_REG, &cmd_reg)); cmd_reg |= FBC_ALTD_START_OP; cmd_reg = SETFIELD(FBC_ALTD_SCOPE, cmd_reg, SCOPE_SYSTEM); cmd_reg = SETFIELD(FBC_ALTD_DROP_PRIORITY, cmd_reg, DROP_PRIORITY_MEDIUM); retry: /* Clear status bits */ - CHECK_ERR(adu_reset(adu)); + CHECK_ERR_GOTO(out, rc = adu_reset(adu)); /* Set the address */ ctrl_reg = SETFIELD(P8_FBC_ALTD_ADDRESS, ctrl_reg, addr); - CHECK_ERR(pib_write(&adu->target, P8_ALTD_CONTROL_REG, ctrl_reg)); + CHECK_ERR_GOTO(out, rc = pib_write(&adu->target, P8_ALTD_CONTROL_REG, ctrl_reg)); /* Start the command */ - CHECK_ERR(pib_write(&adu->target, P8_ALTD_CMD_REG, cmd_reg)); + CHECK_ERR_GOTO(out, rc = pib_write(&adu->target, P8_ALTD_CMD_REG, cmd_reg)); /* Wait for completion */ do { - CHECK_ERR(pib_read(&adu->target, P8_ALTD_STATUS_REG, &val)); + CHECK_ERR_GOTO(out, rc = pib_read(&adu->target, P8_ALTD_STATUS_REG, &val)); } while (!val); if( !(val & FBC_ALTD_ADDR_DONE) || @@ -283,11 +284,12 @@ retry: } /* Read data */ - CHECK_ERR(pib_read(&adu->target, P8_ALTD_DATA_REG, data)); + CHECK_ERR_GOTO(out, rc = pib_read(&adu->target, P8_ALTD_DATA_REG, data)); +out: adu_unlock(adu); + return rc; - return 0; } int p8_adu_putmem(struct adu *adu, uint64_t addr, uint64_t data, int size, int ci) @@ -304,29 +306,29 @@ int p8_adu_putmem(struct adu *adu, uint64_t addr, uint64_t data, int size, int c ctrl_reg = SETFIELD(P8_FBC_ALTD_TTYPE, ctrl_reg, P8_TTYPE_DMA_PARTIAL_WRITE); ctrl_reg = SETFIELD(P8_FBC_ALTD_TSIZE, ctrl_reg, size); - CHECK_ERR(pib_read(&adu->target, P8_ALTD_CMD_REG, &cmd_reg)); + CHECK_ERR_GOTO(out, rc = pib_read(&adu->target, P8_ALTD_CMD_REG, &cmd_reg)); cmd_reg |= FBC_ALTD_START_OP; cmd_reg = SETFIELD(FBC_ALTD_SCOPE, cmd_reg, SCOPE_SYSTEM); cmd_reg = SETFIELD(FBC_ALTD_DROP_PRIORITY, cmd_reg, DROP_PRIORITY_MEDIUM); /* Clear status bits */ - CHECK_ERR(adu_reset(adu)); + CHECK_ERR_GOTO(out, rc = adu_reset(adu)); /* Set the address */ ctrl_reg = SETFIELD(P8_FBC_ALTD_ADDRESS, ctrl_reg, addr); retry: - CHECK_ERR(pib_write(&adu->target, P8_ALTD_CONTROL_REG, ctrl_reg)); + CHECK_ERR_GOTO(out, rc = pib_write(&adu->target, P8_ALTD_CONTROL_REG, ctrl_reg)); /* Write the data */ - CHECK_ERR(pib_write(&adu->target, P8_ALTD_DATA_REG, data)); + CHECK_ERR_GOTO(out, rc = pib_write(&adu->target, P8_ALTD_DATA_REG, data)); /* Start the command */ - CHECK_ERR(pib_write(&adu->target, P8_ALTD_CMD_REG, cmd_reg)); + CHECK_ERR_GOTO(out, rc = pib_write(&adu->target, P8_ALTD_CMD_REG, cmd_reg)); /* Wait for completion */ do { - CHECK_ERR(pib_read(&adu->target, P8_ALTD_STATUS_REG, &val)); + CHECK_ERR_GOTO(out, rc = pib_read(&adu->target, P8_ALTD_STATUS_REG, &val)); } while (!val); if( !(val & FBC_ALTD_ADDR_DONE) || @@ -341,6 +343,7 @@ retry: } } +out: adu_unlock(adu); return rc; diff --git a/libpdbg/operations.h b/libpdbg/operations.h index 96a7c01..dc5042a 100644 --- a/libpdbg/operations.h +++ b/libpdbg/operations.h @@ -29,7 +29,7 @@ } while(0) #define CHECK_ERR_GOTO(label, x) do { \ - if (x) { \ + if ((x)) { \ PRINT_ERR; \ goto label; \ } \