From patchwork Tue Nov 17 15:24:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 7638151 Return-Path: X-Original-To: patchwork-linux-spi@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 0482F9F2EC for ; Tue, 17 Nov 2015 15:27:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3094E204D8 for ; Tue, 17 Nov 2015 15:27:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F463200E7 for ; Tue, 17 Nov 2015 15:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753542AbbKQPZU (ORCPT ); Tue, 17 Nov 2015 10:25:20 -0500 Received: from mail-pa0-f66.google.com ([209.85.220.66]:33743 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750835AbbKQPZR (ORCPT ); Tue, 17 Nov 2015 10:25:17 -0500 Received: by padfb7 with SMTP id fb7so1749065pad.0; Tue, 17 Nov 2015 07:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=G6iBL2j6pVNepSTMrP74M1A+43sdvGMIPvvifIdHSC4=; b=tLLVLssyP7pMTuXJTdjTeb8wRtftLNSkPDti1ZhiBdQ95kVr0XEWzZCxvLr6ezU0I3 ZxiD2H4wjc8k48f0RYtBS6JUD4O1nHsLPIFXcpPc314tjQiM5C7MuPNp8zBSscRgRB3t y7A8Fd9TeTFIQF1Fv3QTIvm6ijfwWQRU9MM1FOUYncXy46KBe3hFdaeTsxXBbPRdfFYO mM0IgWDqvjSg89oUypC+cEx7kaDzzvbvB1FA7SVu0rtyF+nNpRs6eQW8qmsC55Wmr1d0 P3jAwoA3GiZkmz3y8Z/R1YjlM/BfTdm9GPAf3qmTkMj10RPowwSz/ztizRFjzWY/LdtL C+RQ== X-Received: by 10.68.131.201 with SMTP id oo9mr64148293pbb.74.1447773916760; Tue, 17 Nov 2015 07:25:16 -0800 (PST) Received: from localhost.localdomain (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by smtp.gmail.com with ESMTPSA id d7sm43701843pas.31.2015.11.17.07.25.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 07:25:15 -0800 (PST) From: Joshua Clayton To: Mark Brown Cc: Jonathan Corbet , Adrian Remonda , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Joshua Clayton Subject: [PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer Date: Tue, 17 Nov 2015 07:24:21 -0800 Message-Id: <2f17ae29e75967b4522b080c275b907622e1d353.1447773299.git.stillcompiling@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 default_rx and rx are needlessly different. Use one buffer, local to transmit() Signed-off-by: Joshua Clayton --- Documentation/spi/spidev_test.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c index 135b3f5..dfe8f47 100644 --- a/Documentation/spi/spidev_test.c +++ b/Documentation/spi/spidev_test.c @@ -46,7 +46,6 @@ uint8_t default_tx[] = { 0xF0, 0x0D, }; -uint8_t default_rx[ARRAY_SIZE(default_tx)] = {0, }; char *input_tx; static void hex_dump(const void *src, size_t length, size_t line_size, char *prefix) @@ -100,10 +99,10 @@ static int unescape(char *_dst, char *_src, size_t len) return ret; } -static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) +static void transfer(int fd, uint8_t const *tx, size_t len) { int ret; - + uint8_t *rx = malloc(len); struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .rx_buf = (unsigned long)rx, @@ -135,6 +134,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) if (verbose) hex_dump(tx, len, 32, "TX"); hex_dump(rx, len, 32, "RX"); + free(rx); } static void print_usage(const char *prog) @@ -254,7 +254,6 @@ int main(int argc, char *argv[]) int ret = 0; int fd; uint8_t *tx; - uint8_t *rx; int size; parse_opts(argc, argv); @@ -303,13 +302,11 @@ int main(int argc, char *argv[]) if (input_tx) { size = strlen(input_tx+1); tx = malloc(size); - rx = malloc(size); size = unescape((char *)tx, input_tx, size); - transfer(fd, tx, rx, size); - free(rx); + transfer(fd, tx, size); free(tx); } else { - transfer(fd, default_tx, default_rx, sizeof(default_tx)); + transfer(fd, default_tx, sizeof(default_tx)); } close(fd);