Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp331192pxb; Thu, 25 Feb 2021 03:54:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxB5LGqQonuY848gOiFIUQrUIJ030h43pgog/snlGX115V8PhWlx65CWfbxhRnLrPvXdHwd X-Received: by 2002:aa7:cd94:: with SMTP id x20mr2531919edv.53.1614254069740; Thu, 25 Feb 2021 03:54:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614254069; cv=none; d=google.com; s=arc-20160816; b=QCPAyJeC0vozWSUxzc3BLq0usVNEfZS5QlO70VBKsQf6Q0cGsfgmZ9U6hzIJ949kN0 /CgRryH0+P3jvJcZZR1dqnFWZIDRnJRonLiKeomp35YXZrlHPfv7HjRvXoxBO+Fq5HBb c4cQUBe+OGT23hqOW1piLAneS+6Eq1Zx/mK+X1ZGrxpvJm864SEagA/JY789nTzV3C91 OjEIk7IJBF/wdm91wpzzvLnWQA+UGm2GJ52MysSS7QJbxqs+Tk11hzUc9CAvW0RDhmgA ZDKvAnIkK6s+fNs5M9VBRjnze63SLW0CVZ+eRuC4gKcQN11WQ5xGK+8w715bFoR3dRvA 8yvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:date:message-id:from:references:cc:to :subject:dkim-signature; bh=TAhy5sA5EuJAcioqsfiM0ihVQ+DRllhVv2+0h39aJRA=; b=HkWOgTVat2QzSLEVAstoM64qsOhsodLIfNUSEOCIeO2fVV57fOPrf28Umw68NDdEXD N1tvswEyovEx9u8zcZjXSNWwHYmvJa5tFdVvEAF4X3HUPrE+J6vxae3RlJDsELaBjaqq 8fzCNeU8HG2NwbKu7Xc5z0xiqDYwyGehFpYbf1ZF2R875JloAxTUiNaAAB50pNN/kWNA n41zDsLq6nG2900216C5HSoraxATDtBGd8a29xCClPgfq36V3/ry3aZeLqAl/T3FN2oo iLMSSREcgwne9f6lpmW1owHE6deACsjEVzhUGJPcYBcnUAhZPl5e3FdkDpQHnmwICvgg A4TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@opensynergy.com header.s=srmailgate02 header.b=FSfYe2+c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=opensynergy.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u3si563436ejj.14.2021.02.25.03.54.06; Thu, 25 Feb 2021 03:54:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@opensynergy.com header.s=srmailgate02 header.b=FSfYe2+c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=opensynergy.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233375AbhBYLxa (ORCPT + 99 others); Thu, 25 Feb 2021 06:53:30 -0500 Received: from mx1.opensynergy.com ([217.66.60.4]:4564 "EHLO mx1.opensynergy.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233745AbhBYLw0 (ORCPT ); Thu, 25 Feb 2021 06:52:26 -0500 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 6C466A06F5; Thu, 25 Feb 2021 12:51:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=TAhy5sA5EuJA cioqsfiM0ihVQ+DRllhVv2+0h39aJRA=; b=FSfYe2+cHjQSpdAgRO0K0EwGjSoE sk+pRqYuJHY/NMoIfl0gLsM39at7/fRFpL+T0B6aSEO+X1N83R7JNbXnYDr5Ul90 sBHnzHqCm+ef74GlzwclYVV9i4Ba0SU/cOEYMXhIkjj4+yzXySxaohmYIqyAmyxX qLHu6CvcKWapJwGhPdvUk1sCWA26ddTT+9iz8q+yIeZXPDOTk3Fyav1OFo26crIk caU2lFu2crsrKfda6cArThtbmjIZuO9gOgySg5xkYP2SIvazJ8ODNGxy9zswALSQ JAnKl1qXj0tGpoo8NHGt+QjZnw5KDMxZiZGHtsEW3pBqn7ZZ3tk0CIlxYQ== Subject: Re: [PATCH v5 2/9] ALSA: virtio: add virtio sound driver To: Takashi Iwai CC: , , , "Michael S. Tsirkin" , Jaroslav Kysela , Takashi Iwai , Jason Wang , References: <20210222153444.348390-1-anton.yakovlev@opensynergy.com> <20210222153444.348390-3-anton.yakovlev@opensynergy.com> From: Anton Yakovlev Message-ID: Date: Thu, 25 Feb 2021 12:51:36 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.02.2021 11:38, Takashi Iwai wrote: > On Mon, 22 Feb 2021 16:34:37 +0100, > Anton Yakovlev wrote: >> +static int virtsnd_find_vqs(struct virtio_snd *snd) >> +{ >> + struct virtio_device *vdev = snd->vdev; >> + vq_callback_t *callbacks[VIRTIO_SND_VQ_MAX] = { >> + [VIRTIO_SND_VQ_EVENT] = virtsnd_event_notify_cb >> + }; >> + const char *names[VIRTIO_SND_VQ_MAX] = { > > Shouldn't be static? Well, yes. Although in this particular case, I do not think it is that critical. :) > Also it's often const char * const names[] = { ... } > unless you overwrite something. I tried to use the same type names as in the function prototype. Otherwise the compiler or static analyzer may complain. >> +/** >> + * virtsnd_reset_fn() - Kernel worker's function to reset the device. >> + * @work: Reset device work. >> + * >> + * Context: Process context. >> + */ >> +static void virtsnd_reset_fn(struct work_struct *work) >> +{ >> + struct virtio_snd *snd = >> + container_of(work, struct virtio_snd, reset_work); >> + struct virtio_device *vdev = snd->vdev; >> + struct device *dev = &vdev->dev; >> + int rc; >> + >> + dev_info(dev, "sound device needs reset\n"); >> + >> + /* >> + * It seems that the only way to properly reset the device is to remove >> + * and re-create the ALSA sound card device. >> + */ >> + rc = device_reprobe(dev); >> + if (rc) >> + dev_err(dev, "failed to reprobe sound device: %d\n", rc); > > Now I'm wondering whether it's safe to do that from this place. > Basically device_reprobe() unbinds the device that releases the full > resources once including the devm_* stuff. And this work itself is in > a part of devm allocated resource, so it'll be released there. That > said, we might hit use-after-free... This needs to be verified. It's safe. Suicide kernel workers are funny but possible things. Since the kernel itself (AFAIU) assumes such a situation and does not access the worker structure after the callback function call. > thanks, > > Takashi > -- Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin