Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754576Ab2BTVaT (ORCPT ); Mon, 20 Feb 2012 16:30:19 -0500 Received: from mail-ww0-f44.google.com ([74.125.82.44]:39052 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753470Ab2BTVaR (ORCPT ); Mon, 20 Feb 2012 16:30:17 -0500 Authentication-Results: mr.google.com; spf=pass (google.com: domain of egmont@gmail.com designates 10.180.97.196 as permitted sender) smtp.mail=egmont@gmail.com; dkim=pass header.i=egmont@gmail.com MIME-Version: 1.0 In-Reply-To: References: <20120215233002.GB20816@kroah.com> <20120216005437.GA22858@kroah.com> <20120217192825.GE2707@elf.ucw.cz> <20120217225708.0f31f2ac@neptune.home> <20120219221412.1b6912ba@neptune.home> <20120220173106.GA17124@elf.ucw.cz> From: Egmont Koblinger Date: Mon, 20 Feb 2012 22:29:36 +0100 Message-ID: Subject: Re: PROBLEM: Data corruption when pasting large data to terminal To: Pavel Machek Cc: =?UTF-8?Q?Bruno_Pr=C3=A9mont?= , Greg KH , linux-kernel@vger.kernel.org Content-Type: multipart/mixed; boundary=f46d0443067c1bece404b96c00d6 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9591 Lines: 141 --f46d0443067c1bece404b96c00d6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > What does make a difference though, is the read size (rsz). =C2=A0The bug > is reproducible if and only if the read size is a divisor of the > length of the line excluding the terminating newline (i.e. the length > of the full line minus one); that is, a divisor of 62 in this example. Errr, forget this paragraph, this was a bug in my code. When trying to emulate readline, rsz should really be 1. I was not scanning through the whole buffer looking for a newline, and was looking at an incorrect offset. Sorry for the pebkac. Fixed version attached. Anyway, the point is still the same, the data corruption or deadlock are still triggered the same way. thx, egmont --f46d0443067c1bece404b96c00d6 Content-Type: text/x-csrc; charset=US-ASCII; name="ptmx3.c" Content-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cnJubykpOwoJCQlyZXR1cm4gMTsKCQl9CgoJCXB0bXhfc2xhdmVf dGVzdChwdHksIGxpbmUsIHJzeik7CgkJY2xvc2UocHR5KTsKCQlyZXR1cm4gMDsKCX0gZWxzZSB7 CgkJaW50IHM7CgkJcHRteF9tYXN0ZXJfdGVzdChwdHksIGxpbmUsIHdzeik7CgoJCWlmICh3YWl0 cGlkKHBpZCwgJnMsIDApID09IC0xKSB7CgkJCWZwcmludGYoc3RkZXJyLCAiRmFpbGVkIHRvIHdh aXRwaWQoMikgZm9yICVkOiAlc1xuIiwgcGlkLCBzdHJlcnJvcihlcnJubykpOwoJCQlyZXR1cm4g MTsKCQl9CgkJaWYgKFdJRkVYSVRFRChzKSAmJiBXRVhJVFNUQVRVUyhzKSA9PSAwKQoJCQlyZXR1 cm4gMDsKCQlpZiAoV0lGRVhJVEVEKHMpKQoJCQlmcHJpbnRmKHN0ZGVyciwgIkNoaWxkIGV4aXRl ZCB3aXRoICVkXG4iLCBXRVhJVFNUQVRVUyhzKSk7CgkJZWxzZSBpZiAoV0lGU0lHTkFMRUQocykp CgkJCWZwcmludGYoc3RkZXJyLCAiQ2hpbGQgZGllZCB3aXRoIHNpZ25hbCAlZFxuIiwgV1RFUk1T SUcocykpOwoJCWVsc2UKCQkJZnByaW50ZihzdGRlcnIsICJDaGlsZCB0ZXJtaW5hdGVkIGluIGFu IHVua25vd24gd2F5IHdpdGggc3RhdHVzICVkXG4iLCBzKTsKCQlyZXR1cm4gMTsKCX0KfQo= --f46d0443067c1bece404b96c00d6-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/