Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755016AbdC2IvF (ORCPT ); Wed, 29 Mar 2017 04:51:05 -0400 Received: from mail-by2nam01on0064.outbound.protection.outlook.com ([104.47.34.64]:49097 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753694AbdC2Iu6 (ORCPT ); Wed, 29 Mar 2017 04:50:58 -0400 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; gmx.de; dkim=none (message not signed) header.d=none;gmx.de; dmarc=bestguesspass action=none header.from=analog.com; Reply-To: Subject: Re: [PATCH] iio/adc/ltc2497: Driver for Linear Technology LTC2497 ADC References: <1490265310-6162-1-git-send-email-michael.hennerich@analog.com> <6774c073-7fe4-e259-306e-3cf4621f7c69@metafoo.de> To: Lars-Peter Clausen , , , , , CC: , , From: Michael Hennerich Organization: Analog Devices Inc. Message-ID: <025f8461-c823-1f07-5742-e488c3e34f9f@analog.com> Date: Wed, 29 Mar 2017 10:51:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <6774c073-7fe4-e259-306e-3cf4621f7c69@metafoo.de> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(39850400002)(39860400002)(39410400002)(39400400002)(39450400003)(39840400002)(2980300002)(438002)(189002)(199003)(24454002)(76176999)(5660300001)(6666003)(2950100002)(33646002)(53546009)(65826007)(50466002)(31686004)(4326008)(54356999)(50986999)(7636002)(6246003)(4001350100001)(43066003)(229853002)(106466001)(83506001)(305945005)(36756003)(38730400002)(356003)(189998001)(47776003)(2201001)(86362001)(3450700001)(8666007)(31696002)(2906002)(2870700001)(77096006)(8936002)(8676002)(65956001);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR0301MB1543;H:nwd2mta1.analog.com;FPR:;SPF:Pass;MLV:sfv;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD039;1:oNLYCmM3cyOUL26bWR7VYt82R6hzopv3XINPtg3SfjEtZZdIbP0KFeyvGwtg1/eAj61ZUlpKALDIgm5DDkMalxJibkiIdO5nWeD1IIx0iv9dL9TIU1EjVYexOkD9PoKIP1MJZksUsfhbyF9oboZCSz9Gf7dmwrCkpofJuBG3wnkKViGeU7PwAAieSHQXTLJ+17WyY34cUUz3xkvT7hIzE57WP5akezcdoJcXr4P7PoaP9+ok9zlj0JMS06VdDm+EmDuf5KJXOuNXk2Pdqrp9H/NkPYwUh+7QpD5n4uL4DOnqYJWObDMTKL6SJdhf7i6/Q+v9IO+uFGWRHNgSEg3o6fQ3KZ7uqfy/dVmQzVz8SB4rsrT81MIOENEjw1rThwnx0sK+HPLW3Hy6FaixoUBF8mtu6Cqh5ioAE9yLDVJ6GBKc/0is5BNTFGWe7qSAkO6vEQ+DTEtP9iPsBFznvHTm/njCTQZnWCufZApdXPKFtH03mSvGrF5tXoTPhGZq9Xc/JTu9MLQHF9rGA5mBvWiLDyNaazzToczymCkcFa4EFXOA+HcHDiC7Btj6i/fcmsByhcUz5BxWtoV7wyu8R7q9FwfIj45QYP+mSFuZZzhpQ75RKj40KwRZdXZ4VGhGWtbA X-MS-Office365-Filtering-Correlation-Id: 85262164-2015-4273-9719-08d47680ad10 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(8251501002)(2017030254075)(201703131423074)(201703031133080)(201702281549074);SRVR:BY2PR0301MB1543; X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1543;3:yRUCSzoxl5Vt0MWy2oiesDuGanJyU529vWQ+5KSmRuQJtDCC9oi5zjP6QRm5tq6fU6MG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9akYUbDjfjxZkC5ltIh1g86i6XsgIbvgThqWPO6W5Hpi4ixCMrMeu88NvQ8Ax4fx2OQdVqKBFD7T0yF9bslje473lmGI3NOIENYfnM3oUBEllurjXWOzoyXu+HHQVJ4TzaNXTn20uqoIiY4PRRzDI9NMeptmeCo1pHeXJpGfXoCvZ6my90BXNvHKvjvCkyN8PrL9XoDY= X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1543;20:6ydiD1KD9OZ6J/a3DGm3sb92hWAzJr27o9EqEmLc1jbeGgI49l2VnaHlO9g+VI8ePEM10BxPNDmM+OG03BlHZnylVwXz2LS2HqpjTLtTKc8FdNjg3Ks/2qVwXUO+j3IqCQQQ2HMytyDdfYNWTZ6xadtIFOYy7341fjAryUGKbU1TWvdXRdpV7FUktnKs+B8XnpleodBjW7uoJ1116qeGEcqjAxx1yRuTf0wobYrCqMIYtc/ad8O372DJ36I3rQWitMnp+is4qUk34hYwJ4Z5S1mB85mf0UX5E1H0V2abXmsNJBOLma/qj+GiIVr8WUVTgIug9YnHWEH6UctyRQlf7qJbzpQZhR4ZNrM+PxLoquJr5ehppxZO1qtld3K1vNZn3FtHMpYCxdUVMqQWWWKWpR1z26m2ugsj4lbVWECnUuQUzViAIXjOL/TWbhdI7z4F46tKlCGHt9oHXAjLgwcm0QtBDH8P0QVImlJI3no5cjCRdJcrpEGeM6rlhBbwT/ob X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040448)(601004)(2401047)(5005006)(13017025)(8121501046)(13015025)(13018025)(13023025)(13024025)(93006041)(93004041)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(20161123558025)(201703131423073)(201702281528073)(201703061421073)(201703061406073)(6072148);SRVR:BY2PR0301MB1543;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1543; X-Microsoft-Exchange-Diagnostics: 1;BY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-1252?Q?+dmGhIgIgTSrQXThIMlxFIM6c1iMqn50FxyXPwbnCTJj2YuBChyUevMC?= =?Windows-1252?Q?tPVKaRUj8NM90qlEdhtCvo168Q/e/QCL136d6wdj5QHn8xleNh9laO3x?= =?Windows-1252?Q?z2S/Q9M/pXk2AOpEweCjlkR9qoK7bNjGPw3wfraZVPmhJnReiRkuIHU7?= =?Windows-1252?Q?6JfWiOXxW1IQFsPFS9DZygb+qcGt058o9V2VdyUk9u0AF15y9kdF3fGq?= =?Windows-1252?Q?I/DL042maTwGHH3MBVAlXCXiD8dBbwBUpKuNdOSqAoBu+hi5wsjjl0lN?= =?Windows-1252?Q?14Xv0M+bOei0fSFwmr5LTNcAAQM2/1EipmbaYNgrnr/Adx/CHtlyhizb?= =?Windows-1252?Q?8SM6W4VMcVfzgFJGhhPkGprTIp/NQnWNcc/HiYVL4Xil8BYr7hpgHXeP?= =?Windows-1252?Q?/fp6IkRZMpkHUTZ0AP21tq7gRHMUmx1mZHleXR0BVU52sjp7d7AX/aCJ?= =?Windows-1252?Q?tMKzutlqQ4EAEx4XCh2NLY2MjswFUSKA1FgPS3gHSr+A1VETnBHA4666?= =?Windows-1252?Q?Fuj2Vj9za4zw47fIXAuCA+0UaFMnp1BiQiHNzRYA57gEzEyIyy7gM1f/?= =?Windows-1252?Q?PSgFJpg0QkNXAYPTwVpbcBVacs5tJShk44JmZYjkSXGKoAHf+MjnF+Ou?= =?Windows-1252?Q?xa/tyNuHbXI9FKtshuWDnwbMNwv+S3KELXjh6iH31FwPJg71MPIM1qXy?= =?Windows-1252?Q?vq19qEOxsaok9v5su87wxPfobeUE7j58YKAzyYsO3qJ51MHt3EdHjL9r?= =?Windows-1252?Q?u78dqnalmhFJmnr9GiZiYeqBw3WBoJ6j1Q4SYoUTt2rFMr/h5IvElniJ?= =?Windows-1252?Q?aW87VloOLJO9UFhKWdNUEBwhCjio5e/bL0FjSR7V/9Ma9Su8uQKPCPWR?= =?Windows-1252?Q?xCmgp+KNiJkn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cwqBo/mWGqt2Qu1Bz1V1RzzynGU90rqksysK+6Q2UiFHE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1543;7:tNb3NG7X8TWSvQmWbghAoW6/q7FTZU4ySnwF4p4culIMGpEWyxTKbTGU2R4g20CPDzSBY3kpFiZ1uXfZBR8ucsvw8lCGiLiAOrGPsxOqEtghBoAYGyxGxWmgXFgErZ3yb6L1Mfzv4O/+IIMuOCfT7R3/noyzGTWBYrx8pSwBgnz/m4ZM3tn2kQ8X0RYR4L97K5qDF9HI9dKzp0HUvjl8oV53Ln5mgcpijLvEaOGxedBuc/c3sMMKqxnvpISF0qNAgfhocw0bHNs0EocZL1FtUFrnrx1KDx447UQWRDNJbWi1zA6rGfdF9TxHnGXfMIeGnkp6lz8JLwoCmNd6kgdzzQ== X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2017 08:50:39.6427 (UTC) X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.55];Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB1543 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2342 Lines: 86 On 23.03.2017 12:05, Lars-Peter Clausen wrote: Sorry - I missed some of this review feedback ... >> + >> +static int ltc2497_wait_conv(struct ltc2497_st *st) >> +{ >> + s64 time_elapsed; >> + >> + time_elapsed = ktime_ms_delta(ktime_get(), st->time_prev); >> + >> + if (time_elapsed < LTC2497_CONVERSION_TIME_MS) { >> + /* delay if conversion time not passed >> + * since last read or write >> + */ >> + msleep(LTC2497_CONVERSION_TIME_MS - time_elapsed); > > Considering how long this sleeps msleep_interruptible() might be the better > choice. Wondering what should be the outcome of this? We can't simply replace it. Actually I've seen cases here in drivers/iio where the delay is essential, but the return value of msleep_interruptible() is not being checked. Thus causing a malicious access, in case a signal is received. We must delay here. If we switch to msleep_interruptible() the only reason for this would be to cancel the read and return -EINTR to the user. Also there is another msleep below which would also need this kind of handling. > >> + return 0; >> + } >> + >> + if (time_elapsed - LTC2497_CONVERSION_TIME_MS <= 0) { >> + /* We're in automatic mode - >> + * so the last reading is stil not outdated >> + */ >> + return 0; >> + } >> + >> + return -ETIMEDOUT; >> +} >> + >> +static int ltc2497_read(struct ltc2497_st *st, u8 address, int *val) >> +{ >> + struct i2c_client *client = st->client; >> + __be32 buf = 0; > > transfer buffers must not be on the stack to avoid issues if the controller > should use DMA. > >> + int ret; >> + >> + ret = ltc2497_wait_conv(st); >> + if (ret < 0 || st->addr_prev != address) { >> + ret = i2c_smbus_write_byte(st->client, 0xA0 | address); >> + if (ret < 0) >> + return ret; >> + st->addr_prev = address; >> + msleep(LTC2497_CONVERSION_TIME_MS); >> + } >> + ret = i2c_master_recv(client, (char *)&buf, 3); >> + if (ret < 0) { >> + dev_err(&client->dev, "i2c_master_recv failed\n"); >> + return ret; >> + } >> + st->time_prev = ktime_get(); >> + *val = (be32_to_cpu(buf) >> 14) - (1 << 17); >> + >> + return ret; >> +} > [...] > -- Greetings, Michael -- Analog Devices GmbH Otl-Aicher Strasse 60-64 80807 M?nchen Sitz der Gesellschaft M?nchen, Registergericht M?nchen HRB 40368, Gesch?ftsf?hrer: Peter Kolberg, Ali Raza Husain, Eileen Wynne